0.2.6-dev: the lobby flood test floods in bursts until the server closes the socket and waits for the close with a timeout — on a heavily loaded machine one burst of 600 could be read over more than the 1 s drop window, the socket was never closed and the unbounded wait hung the whole file; golden: unchanged

This commit is contained in:
sganggs committed 2026-10-13 06:18:17 +08:00
1 parent bd932158f3
commit d4cdd567dc
1 file changed
+10 -2
+10 -2
View File
@@ -577,8 +577,16 @@ describe('websocket lobby', () => {
test('flooding far beyond the limit closes the socket (1008)', async () => {
const c = await pool.player('Flood');
for (let i = 0; i < 600; i++) c.send({ t: 'ping', c: i, rid: null });
const info = await c.closed;
// bursts until the server closes it: the close needs more than abuseDropsPerSec drops inside one 1 s window, and on
// a heavily loaded machine a single burst of 600 can be read over more than a second — the old single burst then
// never closed the socket and `await c.closed` (no timeout) hung the whole file
const t0 = Date.now();
while (c.isOpen && Date.now() - t0 < 20000) {
for (let i = 0; i < 600 && c.isOpen; i++) c.send({ t: 'ping', c: i, rid: null });
await delay(50);
}
const info = await Promise.race([c.closed, delay(10000).then(() => null)]);
assert.ok(info, 'the server closed the flooding socket');
assert.equal(info.code, 1008);
});