Commit c67d87c926b for nodejs
commit c67d87c926b72ddf5ba9693099dbe0d38e0fa79b
Author: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Date: Sat Dec 5 01:28:25 2026 -0300
test: deflake test-util-throttle
The abort listener check expects the second call to a throttle with a
10 ms window to be queued. If the process is descheduled for 10 ms
between the two calls, the window has already expired and the second
one runs right away without adding the listener. Move the check to
test-util-throttle-timing.js, where the timers and the libuv clock are
mocked.
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67982
Refs: https://github.com/nodejs/reliability/issues/1742
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
diff --git a/test/parallel/test-util-throttle-timing.js b/test/parallel/test-util-throttle-timing.js
index 56b6c7716a9..28d0c1f95a9 100644
--- a/test/parallel/test-util-throttle-timing.js
+++ b/test/parallel/test-util-throttle-timing.js
@@ -3,6 +3,7 @@
const common = require('../common');
const assert = require('node:assert');
+const { listenerCount } = require('node:events');
const { mock } = require('node:test');
const { setImmediate } = require('node:timers/promises');
const { internalBinding } = require('internal/test/binding');
@@ -167,4 +168,19 @@ process.on('unhandledRejection', common.mustNotCall());
assert.deepStrictEqual(await Promise.all([first, recursive]), [1, 2]);
assert.deepStrictEqual(values, [1, 2]);
}
+
+ {
+ const { signal } = new AbortController();
+ const throttled = throttle(common.mustCall((value) => value, 2), 1, 10, {
+ signal,
+ });
+ assert.strictEqual(listenerCount(signal, 'abort'), 0);
+ const first = throttled(1);
+ assert.strictEqual(listenerCount(signal, 'abort'), 0);
+ const second = throttled(2);
+ assert.strictEqual(listenerCount(signal, 'abort'), 1);
+ mock.timers.tick(10);
+ assert.deepStrictEqual(await Promise.all([first, second]), [1, 2]);
+ assert.strictEqual(listenerCount(signal, 'abort'), 0);
+ }
})().then(common.mustCall()).finally(() => mock.reset());
diff --git a/test/parallel/test-util-throttle.js b/test/parallel/test-util-throttle.js
index f03c5ef0da7..8eb2ce2d147 100644
--- a/test/parallel/test-util-throttle.js
+++ b/test/parallel/test-util-throttle.js
@@ -262,20 +262,6 @@ throttle(() => {}, 1, 1, {
);
}
- {
- const { signal } = new AbortController();
- const throttled = throttle(common.mustCall((value) => value, 2), 1, 10, {
- signal,
- });
- assert.strictEqual(abortListenerCount(signal), 0);
- const first = throttled(1);
- assert.strictEqual(abortListenerCount(signal), 0);
- const second = throttled(2);
- assert.strictEqual(abortListenerCount(signal), 1);
- assert.deepStrictEqual(await Promise.all([first, second]), [1, 2]);
- assert.strictEqual(abortListenerCount(signal), 0);
- }
-
{
const { signal } = new AbortController();
const throttled = throttle(common.mustCall(), 1, TIMEOUT_MAX, { signal });