Skip to content

Tests listen on ports the system chooses - #56

Merged
RhysSullivan merged 1 commit into
mainfrom
tests-free-ports
Nov 27, 2026
Merged

RhysSullivan merged 1 commit into
mainfrom
tests-free-ports

Conversation

@RhysSullivan

Copy link
Copy Markdown

Thirteen test files bound fixed ports (41873 to 41941, and 14000 to 14060 in the emulate api tests). CI's parallel package suites and ephemeral client ports could take them first, and context.test.ts and the mcp Okta test even shared 41893. Each collision showed up as a stray fetch failed in a package the change under test did not touch.

  • serveOnFreePort (new in @emulators/core, next to serve) binds port 0 and holds the socket from the start. It takes the emulator's handler once the emulator is built for the bound address, and answers 503 until then. Nothing else can take the port in between.
  • The changed servers: ten single-server files, the WorkOS file's second server, and both servers in each mcp enterprise test now use it. The emulate api tests ask createEmulator for port 0 and check the URL against the reported port.
  • Collection-time URLs: URLs built from the base address when tests are collected (SUCCESS_URL, RETURN_URL, PlanetScale's MCP URL, Miro's challenge) are now read when called.

Tests only, apart from the new export. The full suite passed three times in a row uncached (turbo run test --force).

Thirteen test files bound fixed ports (41873 to 41941, 14000 to 14060),
which CI's parallel package suites and ephemeral client ports could take
first; context.test.ts and the mcp Okta test even shared 41893. Each
failure showed as a stray `fetch failed` in a package the change did not
touch.

Every server a test starts now binds port 0 through `serveOnFreePort` in
@emulators/core, which holds the socket from the start and takes the
emulator's handler once it is built for the bound address. The api tests
ask createEmulator for port 0. URLs derived from the base address at
collection time are read when called instead.
@RhysSullivan
RhysSullivan marked this pull request as ready for review November 27, 2026 02:45
@RhysSullivan
RhysSullivan merged commit 90a3156 into main Nov 27, 2026
1 check passed
@RhysSullivan RhysSullivan mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant