Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4416ffa

Browse filesBrowse files
addaleaxcjihrig
authored andcommitted
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: #7919 PR-URL: #7933 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent fb8840c commit 4416ffa
Copy full SHA for 4416ffa

File tree

Expand file treeCollapse file tree

4 files changed

+29
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+29
-6
lines changed
Open diff view settings
Collapse file

‎src/node_util.cc‎

Copy file name to clipboardExpand all lines: src/node_util.cc
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
103103
args.GetReturnValue().Set(had_pending_signals);
104104
}
105105

106+
107+
void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
108+
bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
109+
args.GetReturnValue().Set(ret);
110+
}
111+
112+
106113
void Initialize(Local<Object> target,
107114
Local<Value> unused,
108115
Local<Context> context) {
@@ -118,6 +125,7 @@ void Initialize(Local<Object> target,
118125

119126
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
120127
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
128+
env->SetMethod(target, "watchdogHasPendingSigint", WatchdogHasPendingSigint);
121129
}
122130

123131
} // namespace util
Collapse file

‎src/node_watchdog.cc‎

Copy file name to clipboardExpand all lines: src/node_watchdog.cc
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ bool SigintWatchdogHelper::Stop() {
258258
}
259259

260260

261+
bool SigintWatchdogHelper::HasPendingSignal() {
262+
Mutex::ScopedLock lock(list_mutex_);
263+
264+
return has_pending_signal_;
265+
}
266+
267+
261268
void SigintWatchdogHelper::Register(SigintWatchdog* wd) {
262269
Mutex::ScopedLock lock(list_mutex_);
263270

Collapse file

‎src/node_watchdog.h‎

Copy file name to clipboardExpand all lines: src/node_watchdog.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SigintWatchdogHelper {
6363
static SigintWatchdogHelper* GetInstance() { return &instance; }
6464
void Register(SigintWatchdog* watchdog);
6565
void Unregister(SigintWatchdog* watchdog);
66+
bool HasPendingSignal();
6667

6768
int Start();
6869
bool Stop();
Collapse file

‎test/parallel/test-util-sigint-watchdog.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-sigint-watchdog.js
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,41 @@ if (common.isWindows) {
2020
// Test with one call to the watchdog, one signal.
2121
binding.startSigintWatchdog();
2222
process.kill(process.pid, 'SIGINT');
23-
setTimeout(common.mustCall(() => {
23+
waitForPendingSignal(common.mustCall(() => {
2424
const hadPendingSignals = binding.stopSigintWatchdog();
2525
assert.strictEqual(hadPendingSignals, true);
2626
next();
27-
}), common.platformTimeout(100));
27+
}));
2828
},
2929
(next) => {
3030
// Nested calls are okay.
3131
binding.startSigintWatchdog();
3232
binding.startSigintWatchdog();
3333
process.kill(process.pid, 'SIGINT');
34-
setTimeout(common.mustCall(() => {
34+
waitForPendingSignal(common.mustCall(() => {
3535
const hadPendingSignals1 = binding.stopSigintWatchdog();
3636
const hadPendingSignals2 = binding.stopSigintWatchdog();
3737
assert.strictEqual(hadPendingSignals1, true);
3838
assert.strictEqual(hadPendingSignals2, false);
3939
next();
40-
}), common.platformTimeout(100));
40+
}));
4141
},
4242
() => {
4343
// Signal comes in after first call to stop.
4444
binding.startSigintWatchdog();
4545
binding.startSigintWatchdog();
4646
const hadPendingSignals1 = binding.stopSigintWatchdog();
4747
process.kill(process.pid, 'SIGINT');
48-
setTimeout(common.mustCall(() => {
48+
waitForPendingSignal(common.mustCall(() => {
4949
const hadPendingSignals2 = binding.stopSigintWatchdog();
5050
assert.strictEqual(hadPendingSignals1, false);
5151
assert.strictEqual(hadPendingSignals2, true);
52-
}), common.platformTimeout(100));
52+
}));
5353
}].reduceRight((a, b) => common.mustCall(b).bind(null, a))();
54+
55+
function waitForPendingSignal(cb) {
56+
if (binding.watchdogHasPendingSigint())
57+
cb();
58+
else
59+
setTimeout(waitForPendingSignal, 10, cb);
60+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.