Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add coverage for vm's breakOnSigint option #12512

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions test/parallel/test-vm-sigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ const vm = require('vm');

const spawn = require('child_process').spawn;

const methods = [
'runInThisContext',
'runInContext'
];

if (common.isWindows) {
// No way to send CTRL_C_EVENT to processes from JS right now.
common.skip('platform not supported');
Expand All @@ -18,31 +13,38 @@ if (common.isWindows) {

if (process.argv[2] === 'child') {
const method = process.argv[3];
const listeners = +process.argv[4];
assert.ok(method);
assert.ok(typeof listeners, 'number');

const script = `process.send('${method}'); while(true) {}`;
const args = method === 'runInContext' ?
[vm.createContext({ process })] :
[];
const options = { breakOnSigint: true };

for (let i = 0; i < listeners; i++)
process.on('SIGINT', common.noop);

assert.throws(() => { vm[method](script, ...args, options); },
/^Error: Script execution interrupted\.$/);

return;
}

for (const method of methods) {
const child = spawn(process.execPath, [__filename, 'child', method], {
stdio: [null, 'pipe', 'inherit', 'ipc']
});

child.on('message', common.mustCall(() => {
process.kill(child.pid, 'SIGINT');
}));

child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(signal, null);
assert.strictEqual(code, 0);
}));
for (const method of ['runInThisContext', 'runInContext']) {
for (const listeners of [0, 1, 2]) {
const args = [__filename, 'child', method, listeners];
const child = spawn(process.execPath, args, {
stdio: [null, 'pipe', 'inherit', 'ipc']
});

child.on('message', common.mustCall(() => {
process.kill(child.pid, 'SIGINT');
}));

child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(signal, null);
assert.strictEqual(code, 0);
}));
}
}