Skip to content

Commit

Permalink
test: fix unreliable async-hooks/test-signalwrap
Browse files Browse the repository at this point in the history
Use an interval to keep the event loop open so the test does not exit
before receiving all signals fom asynchronous `exec()` calls.

PR-URL: #17827
Fixes: #14070
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information
Trott authored and rvagg committed Aug 16, 2018
1 parent 7c6e391 commit 7d263ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/async-hooks/test-signalwrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
const common = require('../common');

if (common.isWindows) return common.skip('no signals in Windows');
if (common.isWindows)
common.skip('no signals in Windows');

const assert = require('assert');
const initHooks = require('./init-hooks');
Expand All @@ -11,6 +12,10 @@ const exec = require('child_process').exec;
const hooks = initHooks();

hooks.enable();

// Keep the event loop open so process doesn't exit before receiving signals.
const interval = setInterval(() => {}, 9999);

process.on('SIGUSR2', common.mustCall(onsigusr2, 2));

const as = hooks.activitiesOfTypes('SIGNALWRAP');
Expand Down Expand Up @@ -66,6 +71,7 @@ function onsigusr2() {
}

function onsigusr2Again() {
clearInterval(interval);
setImmediate(() => {
checkInvocations(
signal1, { init: 1, before: 2, after: 2, destroy: 1 },
Expand Down

0 comments on commit 7d263ff

Please sign in to comment.