export type EnsureTiming = { readonly pollInterval: number readonly requestTimeout: number readonly spawnDelay: number readonly maxSpawnDelay: number readonly promiseTimeout: number readonly stopPollInterval: number readonly stopPollAttempts: number } const timings = new WeakMap() // A freshly spawned service registers in ~250 ms, so the poll cadence is a large share of the // time a client waits for it. Probes are sequential, so the wait between them only matters while // the connection is refused; both variants give up after promiseTimeout of wall-clock time. export const defaultEnsureTiming: EnsureTiming = { pollInterval: 25, requestTimeout: 2_000, spawnDelay: 5_000, maxSpawnDelay: 30_000, promiseTimeout: 120_000, stopPollInterval: 50, stopPollAttempts: 100, } export function ensureTiming(options: object) { return timings.get(options) ?? defaultEnsureTiming } // Keep test timing out of the public lifecycle option types. export function withEnsureTiming(options: A, overrides: Partial): A { timings.set(options, { ...defaultEnsureTiming, ...overrides }) return options }