test(cli): de-flake close-flush assertion (poll for the server close event)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-09-08 23:21:53 +01:00
parent 6c46b52964
commit 629fd1652d

View File

@@ -200,10 +200,16 @@ describe("createWsLifecycle — close() flushes the close handshake (spec addend
});
const { handle } = makeClient(broker.url);
await handle.ready;
const t0 = Date.now();
await handle.close();
// The broker side has already seen the close frame when close() resolves.
// close() waited for the handshake: the client socket is fully CLOSED
// (not merely CLOSING) and the broker's own close event lands within a
// few ms — well inside CLOSE_FLUSH_MS, not after a process.exit.
expect(handle.ws?.readyState).toBe(3 /* CLOSED */);
for (let i = 0; i < 30 && serverCloses.length === 0; i++) await sleep(10);
expect(serverCloses).toHaveLength(1);
expect(serverCloses[0]).toBe(1005); // close() without a code → no status
expect(Date.now() - t0).toBeLessThan(1_000);
expect(handle.status).toBe("closed");
});
});