test: fix test-sync-io-option
This test was failing occasionally both locally and on CI. Switched from using spawn to execFile for a more reliable test. Fixes: https://github.com/nodejs/io.js/issues/1837 PR-URL: https://github.com/nodejs/io.js/pull/1840 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
4ed25f664d
commit
43a82f8a71
@ -1,8 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const spawn = require('child_process').spawn;
|
const execFile = require('child_process').execFile;
|
||||||
|
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
setImmediate(function() {
|
setImmediate(function() {
|
||||||
@ -14,34 +13,23 @@ if (process.argv[2] === 'child') {
|
|||||||
(function runTest(flags) {
|
(function runTest(flags) {
|
||||||
var execArgv = [flags.pop()];
|
var execArgv = [flags.pop()];
|
||||||
var args = [__filename, 'child'];
|
var args = [__filename, 'child'];
|
||||||
var child = spawn(process.execPath, execArgv.concat(args));
|
var cntr = 0;
|
||||||
var stderr = '';
|
args = execArgv.concat(args);
|
||||||
|
if (!args[0]) args.shift();
|
||||||
child.stdout.on('data', function(chunk) {
|
execFile(process.execPath, args, function(err, stdout, stderr) {
|
||||||
throw new Error('UNREACHABLE');
|
assert.equal(err, null);
|
||||||
});
|
assert.equal(stdout, '');
|
||||||
|
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
|
||||||
child.stderr.on('data', function(chunk) {
|
cntr++;
|
||||||
stderr += chunk.toString();
|
if (args[0] === '--trace-sync-io') {
|
||||||
});
|
assert.equal(cntr, 1);
|
||||||
|
} else if (args[0] === __filename) {
|
||||||
child.on('close', function() {
|
assert.equal(cntr, 0);
|
||||||
var cntr1 = (stderr.match(/WARNING/g) || []).length;
|
|
||||||
var cntr2 = (stderr.match(/fs\.readFileSync/g) || []).length;
|
|
||||||
assert.equal(cntr1, cntr2);
|
|
||||||
if (execArgv[0] === '--trace-sync-io') {
|
|
||||||
// Prints 4 WARNINGS for --trace-sync-io. 1 for each sync call
|
|
||||||
// inside readFileSync
|
|
||||||
assert.equal(cntr1, 4);
|
|
||||||
} else if (execArgv[0] === ' ') {
|
|
||||||
assert.equal(cntr1, 0);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('UNREACHABLE');
|
throw new Error('UNREACHABLE');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags.length > 0)
|
if (flags.length > 0)
|
||||||
setImmediate(runTest, flags);
|
setImmediate(runTest, flags);
|
||||||
});
|
});
|
||||||
}(['--trace-sync-io', ' ']));
|
}(['--trace-sync-io', '']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user