2016-05-08 03:30:23 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2016-05-29 17:53:40 +02:00
|
|
|
if (common.isWindows) {
|
2016-05-08 03:30:23 +02:00
|
|
|
// No way to send CTRL_C_EVENT to processes from JS right now.
|
|
|
|
common.skip('platform not supported');
|
|
|
|
}
|
2025-01-22 14:19:38 -08:00
|
|
|
|
|
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
|
|
|
|
if (!isMainThread) {
|
2018-05-18 01:20:25 +02:00
|
|
|
common.skip('No signal handling available in Workers');
|
2025-01-22 14:19:38 -08:00
|
|
|
}
|
2016-05-08 03:30:23 +02:00
|
|
|
|
2017-07-01 02:29:09 +03:00
|
|
|
const assert = require('assert');
|
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
|
2016-05-08 03:30:23 +02:00
|
|
|
const child = spawn(process.execPath, [ '-i' ], {
|
2022-11-12 18:56:08 -08:00
|
|
|
stdio: [null, null, 2, 'ipc']
|
2016-05-08 03:30:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let stdout = '';
|
|
|
|
child.stdout.setEncoding('utf8');
|
|
|
|
child.stdout.on('data', function(c) {
|
|
|
|
stdout += c;
|
|
|
|
});
|
|
|
|
|
|
|
|
child.stdout.once('data', common.mustCall(() => {
|
2022-11-12 18:56:08 -08:00
|
|
|
child.on('message', common.mustCall((msg) => {
|
|
|
|
assert.strictEqual(msg, 'repl is busy');
|
2016-05-08 03:30:23 +02:00
|
|
|
process.kill(child.pid, 'SIGINT');
|
|
|
|
child.stdout.once('data', common.mustCall(() => {
|
|
|
|
// Make sure REPL still works.
|
|
|
|
child.stdin.end('"foobar"\n');
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
2022-11-12 18:56:08 -08:00
|
|
|
child.stdin.write(
|
|
|
|
'vm.runInThisContext("process.send(\'repl is busy\'); while(true){}", ' +
|
|
|
|
'{ breakOnSigint: true });\n'
|
|
|
|
);
|
2016-05-08 03:30:23 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
child.on('close', function(code) {
|
2018-04-19 18:41:33 +08:00
|
|
|
const expected = 'Script execution was interrupted by `SIGINT`';
|
2017-02-10 13:54:41 -08:00
|
|
|
assert.ok(
|
2018-04-19 18:41:33 +08:00
|
|
|
stdout.includes(expected),
|
|
|
|
`Expected stdout to contain "${expected}", got ${stdout}`
|
2017-02-10 13:54:41 -08:00
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
stdout.includes('foobar'),
|
|
|
|
`Expected stdout to contain "foobar", got ${stdout}`
|
|
|
|
);
|
2016-05-08 03:30:23 +02:00
|
|
|
});
|