Skip to content

Commit a84d50c

Browse files
committed
fix(mongo): make client reconnect test more robust
The test was flaky because await sleep(0) doesn't always give enough time for TCP close events to propagate through the event loop, especially under CPU contention when multiple CI runners execute jobs in parallel. Now waits up to 1 second for the connection to actually close.
1 parent 22483a2 commit a84d50c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/mongo/tests/client/mong-env.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ describe('mongo-env', () => {
100100
}
101101

102102
mongo.closeConnections();
103-
await sleep(0);
103+
// Wait for close event to propagate (may take a few event loop ticks under load)
104+
for (let i = 0; i < 100 && client.pool.isConnected(); i++) {
105+
await sleep(0.01);
106+
}
104107
expect(client.pool.isConnected()).toBe(false);
105108

106109
{

0 commit comments

Comments
 (0)