summaryrefslogtreecommitdiff
path: root/test/parallel/test-util-sigint-watchdog.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-08-01 12:58:24 +0200
committerAnna Henningsen <anna@addaleax.net>2016-08-11 18:42:41 +0200
commit6d3241d19c89427b79324ce348d7f42dee5b7531 (patch)
tree9d1abba7f38372d22d55c2bcb0dcccb9f2192cf1 /test/parallel/test-util-sigint-watchdog.js
parent84f07782470dd515bfc8fcc3f0c70e03848eb593 (diff)
downloadandroid-node-v8-6d3241d19c89427b79324ce348d7f42dee5b7531.tar.gz
android-node-v8-6d3241d19c89427b79324ce348d7f42dee5b7531.tar.bz2
android-node-v8-6d3241d19c89427b79324ce348d7f42dee5b7531.zip
test,util: fix flaky test-util-sigint-watchdog
Fix parallel/test-util-sigint-watchdog by polling until the signal has definitely been received instead of just using a timeout. Fixes: https://github.com/nodejs/node/issues/7919 PR-URL: https://github.com/nodejs/node/pull/7933 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-util-sigint-watchdog.js')
-rw-r--r--test/parallel/test-util-sigint-watchdog.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/test/parallel/test-util-sigint-watchdog.js b/test/parallel/test-util-sigint-watchdog.js
index f9bb3ecd93..42e4048bd7 100644
--- a/test/parallel/test-util-sigint-watchdog.js
+++ b/test/parallel/test-util-sigint-watchdog.js
@@ -20,24 +20,24 @@ if (common.isWindows) {
// Test with one call to the watchdog, one signal.
binding.startSigintWatchdog();
process.kill(process.pid, 'SIGINT');
- setTimeout(common.mustCall(() => {
+ waitForPendingSignal(common.mustCall(() => {
const hadPendingSignals = binding.stopSigintWatchdog();
assert.strictEqual(hadPendingSignals, true);
next();
- }), common.platformTimeout(100));
+ }));
},
(next) => {
// Nested calls are okay.
binding.startSigintWatchdog();
binding.startSigintWatchdog();
process.kill(process.pid, 'SIGINT');
- setTimeout(common.mustCall(() => {
+ waitForPendingSignal(common.mustCall(() => {
const hadPendingSignals1 = binding.stopSigintWatchdog();
const hadPendingSignals2 = binding.stopSigintWatchdog();
assert.strictEqual(hadPendingSignals1, true);
assert.strictEqual(hadPendingSignals2, false);
next();
- }), common.platformTimeout(100));
+ }));
},
() => {
// Signal comes in after first call to stop.
@@ -45,9 +45,16 @@ if (common.isWindows) {
binding.startSigintWatchdog();
const hadPendingSignals1 = binding.stopSigintWatchdog();
process.kill(process.pid, 'SIGINT');
- setTimeout(common.mustCall(() => {
+ waitForPendingSignal(common.mustCall(() => {
const hadPendingSignals2 = binding.stopSigintWatchdog();
assert.strictEqual(hadPendingSignals1, false);
assert.strictEqual(hadPendingSignals2, true);
- }), common.platformTimeout(100));
+ }));
}].reduceRight((a, b) => common.mustCall(b).bind(null, a))();
+
+function waitForPendingSignal(cb) {
+ if (binding.watchdogHasPendingSigint())
+ cb();
+ else
+ setTimeout(waitForPendingSignal, 10, cb);
+}