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>
This commit is contained in:
parent
84f0778247
commit
6d3241d19c
@ -113,6 +113,13 @@ void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
|
||||
args.GetReturnValue().Set(had_pending_signals);
|
||||
}
|
||||
|
||||
|
||||
void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
|
||||
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
|
||||
args.GetReturnValue().Set(ret);
|
||||
}
|
||||
|
||||
|
||||
void Initialize(Local<Object> target,
|
||||
Local<Value> unused,
|
||||
Local<Context> context) {
|
||||
@ -138,6 +145,7 @@ void Initialize(Local<Object> target,
|
||||
|
||||
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
|
||||
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
|
||||
env->SetMethod(target, "watchdogHasPendingSigint", WatchdogHasPendingSigint);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
@ -258,6 +258,13 @@ bool SigintWatchdogHelper::Stop() {
|
||||
}
|
||||
|
||||
|
||||
bool SigintWatchdogHelper::HasPendingSignal() {
|
||||
Mutex::ScopedLock lock(list_mutex_);
|
||||
|
||||
return has_pending_signal_;
|
||||
}
|
||||
|
||||
|
||||
void SigintWatchdogHelper::Register(SigintWatchdog* wd) {
|
||||
Mutex::ScopedLock lock(list_mutex_);
|
||||
|
||||
|
@ -63,6 +63,7 @@ class SigintWatchdogHelper {
|
||||
static SigintWatchdogHelper* GetInstance() { return &instance; }
|
||||
void Register(SigintWatchdog* watchdog);
|
||||
void Unregister(SigintWatchdog* watchdog);
|
||||
bool HasPendingSignal();
|
||||
|
||||
int Start();
|
||||
bool Stop();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user