The intention of test case is to make sure that `timeout` property is honored and the code in context terminates and throws correct exception. However in test case, the code inside context would complete before `timeout` for windows and would sometimes fail. Updated the code so it guarantee to not complete execution until timeout is triggered. Fixes: https://github.com/nodejs/node/issues/11261 PR-URL: https://github.com/nodejs/node/pull/11530 Reviewed-By: James M Snell <jasnell.gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
23 lines
558 B
JavaScript
23 lines
558 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const vm = require('vm');
|
|
const spawn = require('child_process').spawn;
|
|
|
|
if (process.argv[2] === 'child') {
|
|
const code = 'while(true);';
|
|
|
|
const ctx = vm.createContext();
|
|
|
|
vm.runInContext(code, ctx, { timeout: 1 });
|
|
} else {
|
|
const proc = spawn(process.execPath, process.argv.slice(1).concat('child'));
|
|
let err = '';
|
|
proc.stderr.on('data', function(data) {
|
|
err += data;
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(/Script execution timed out/.test(err));
|
|
});
|
|
}
|