Skip to content

Commit 71a54aa

Browse files
panvaaduh95
authored andcommitted
test: collect timeout signals explicitly
Force collection on a later turn while the timeout sources are only retained by AbortSignal.any(). Shorten the first timeout and clear the watchdog after the assertion. This preserves the source-retention regression check without waiting ten seconds on successful runs. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #65980 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent 1a15aff commit 71a54aa

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1+
// Flags: --expose-gc
12
'use strict';
23

3-
require('../common');
4+
const common = require('../common');
45
const assert = require('assert');
56
const { once } = require('node:events');
67
const { describe, it } = require('node:test');
78

89
describe('AbortSignal.any() with timeout signals', () => {
910
it('should abort when the first timeout signal fires', async () => {
10-
const signal = AbortSignal.any([AbortSignal.timeout(9000), AbortSignal.timeout(110000)]);
11+
const signal = AbortSignal.any([
12+
AbortSignal.timeout(common.platformTimeout(1000)),
13+
AbortSignal.timeout(110000),
14+
]);
15+
let timeout;
1116

1217
const abortPromise = Promise.race([
1318
once(signal, 'abort').then(() => {
1419
throw signal.reason;
1520
}),
16-
new Promise((resolve) => setTimeout(resolve, 10000)),
21+
new Promise((resolve) => {
22+
timeout = setTimeout(resolve, common.platformTimeout(10000));
23+
}),
1724
]);
1825

19-
// The promise should be aborted by the 9000ms timeout
20-
await assert.rejects(
21-
() => abortPromise,
22-
{
23-
name: 'TimeoutError',
24-
message: 'The operation was aborted due to timeout'
25-
}
26-
);
26+
// Collect after this turn so the WeakRefs no longer keep the timeout
27+
// signals alive by themselves.
28+
setImmediate(common.mustCall(() => globalThis.gc()));
29+
30+
try {
31+
await assert.rejects(
32+
() => abortPromise,
33+
{
34+
name: 'TimeoutError',
35+
message: 'The operation was aborted due to timeout'
36+
}
37+
);
38+
} finally {
39+
clearTimeout(timeout);
40+
}
2741
});
2842
});

0 commit comments

Comments
 (0)