11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// This test is to assert that we can SIGINT a script which loops forever.
31cb0ef41Sopenharmony_ci// Ref(http):
41cb0ef41Sopenharmony_ci// groups.google.com/group/nodejs-dev/browse_thread/thread/e20f2f8df0296d3f
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst spawn = require('child_process').spawn;
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconsole.log('start');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst c = spawn(process.execPath, ['-e', 'while(true) { console.log("hi"); }']);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cilet sentKill = false;
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cic.stdout.on('data', function(s) {
161cb0ef41Sopenharmony_ci  // Prevent race condition:
171cb0ef41Sopenharmony_ci  // Wait for the first bit of output from the child process
181cb0ef41Sopenharmony_ci  // so that we're sure that it's in the V8 event loop and not
191cb0ef41Sopenharmony_ci  // just in the startup phase of execution.
201cb0ef41Sopenharmony_ci  if (!sentKill) {
211cb0ef41Sopenharmony_ci    c.kill('SIGINT');
221cb0ef41Sopenharmony_ci    console.log('SIGINT infinite-loop.js');
231cb0ef41Sopenharmony_ci    sentKill = true;
241cb0ef41Sopenharmony_ci  }
251cb0ef41Sopenharmony_ci});
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_cic.on('exit', common.mustCall(function(code) {
281cb0ef41Sopenharmony_ci  assert.ok(code !== 0);
291cb0ef41Sopenharmony_ci  console.log('killed infinite-loop.js');
301cb0ef41Sopenharmony_ci}));
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciprocess.on('exit', function() {
331cb0ef41Sopenharmony_ci  assert.ok(sentKill);
341cb0ef41Sopenharmony_ci});
35