1'use strict';
2// This test is to assert that we can SIGINT a script which loops forever.
3// Ref(http):
4// groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
5const common = require('../common');
6const assert = require('assert');
7const spawn = require('child_process').spawn;
8
9console.log('start');
10
11const c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']);
12
13let sentKill = false;
14
15c.stdout.on('data', function(s) {
16  // Prevent race condition:
17  // Wait for the first bit of output from the child process
18  // so that we're sure that it's in the V8 event loop and not
19  // just in the startup phase of execution.
20  if (!sentKill) {
21    c.kill('SIGINT');
22    console.log('SIGINT infinite-loop.js');
23    sentKill = true;
24  }
25});
26
27c.on('exit', common.mustCall(function(code) {
28  assert.ok(code !== 0);
29  console.log('killed infinite-loop.js');
30}));
31
32process.on('exit', function() {
33  assert.ok(sentKill);
34});
35