mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
04b4d15b39
Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
35 lines
944 B
JavaScript
35 lines
944 B
JavaScript
'use strict';
|
|
// This test is to assert that we can SIGINT a script which loops forever.
|
|
// Ref(http):
|
|
// groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
|
|
const common = require('../common');
|
|
var assert = require('assert');
|
|
var spawn = require('child_process').spawn;
|
|
|
|
console.log('start');
|
|
|
|
var c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']);
|
|
|
|
var sentKill = false;
|
|
|
|
c.stdout.on('data', function(s) {
|
|
// Prevent race condition:
|
|
// Wait for the first bit of output from the child process
|
|
// so that we're sure that it's in the V8 event loop and not
|
|
// just in the startup phase of execution.
|
|
if (!sentKill) {
|
|
c.kill('SIGINT');
|
|
console.log('SIGINT infinite-loop.js');
|
|
sentKill = true;
|
|
}
|
|
});
|
|
|
|
c.on('exit', common.mustCall(function(code) {
|
|
assert.ok(code !== 0);
|
|
console.log('killed infinite-loop.js');
|
|
}));
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(sentKill);
|
|
});
|