startTestHub function

Future<TestHub> startTestHub({
  1. String session = 'test_session',
  2. String secret = 'test-secret-not-for-real-use',
  3. WsLimits limits = const WsLimits(),
  4. Duration? sessionTtl,
})

Starts a hub on an ephemeral port with a fixed, throwaway secret.

The secret is a constant on purpose: these hubs live on loopback for the length of one test, and a readable value makes a failing handshake easy to reason about. Never use it for anything reachable.

Implementation

Future<TestHub> startTestHub({
  String session = 'test_session',
  String secret = 'test-secret-not-for-real-use',
  WsLimits limits = const WsLimits(),
  Duration? sessionTtl,
}) async {
  final credentials = HubCredentials(session: session, secret: secret);
  final hub = await CoordinationHub.serve(
    credentials: credentials,
    limits: limits,
    sessionTtl: sessionTtl,
  );
  return TestHub(hub, credentials);
}