The Node test server starts asynchronously, but test-engine/server/server.mjs currently calls server.listen(port) without exposing or awaiting readiness.
In consumers that start the server via side-effect import, for example:
await import('./test-engine/server/server.mjs')
await runTests(...)
the import can resolve before the server has emitted listening. On slower platforms, especially Windows CI, the first client request can race server startup and fail intermittently.
Observed symptoms:
SERVER WARNING: State not found for <uuid>
Error: Process completed with exit code 1
The likely sequence is:
- Worker imports
server.mjs.
server.listen(port) is called, but the server is not ready yet.
- Test setup sends
PUT /config/<uuid>.
- The request can fail before the server accepts connections.
- The harness continues to later
GET /state/<uuid>.
- Since no config/state was created, the server logs
State not found.
Suggested fix:
await new Promise((resolve, reject) => {
server.once('listening', resolve)
server.once('error', reject)
server.listen(port)
})
This preserves the existing side-effect import behavior while making await import('./server.mjs') mean the server is actually listening before tests proceed.
This was found while running Undici’s cache interceptor test harness against the vendored cache-tests submodule in nodejs/undici#5199
The Node test server starts asynchronously, but
test-engine/server/server.mjscurrently callsserver.listen(port)without exposing or awaiting readiness.In consumers that start the server via side-effect import, for example:
the import can resolve before the server has emitted
listening. On slower platforms, especially Windows CI, the first client request can race server startup and fail intermittently.Observed symptoms:
The likely sequence is:
server.mjs.server.listen(port)is called, but the server is not ready yet.PUT /config/<uuid>.GET /state/<uuid>.State not found.Suggested fix:
This preserves the existing side-effect import behavior while making
await import('./server.mjs')mean the server is actually listening before tests proceed.This was found while running Undici’s cache interceptor test harness against the vendored
cache-testssubmodule in nodejs/undici#5199