Skip to content

Commit 43a82f8

Browse files
committed
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: #1837 PR-URL: #1840 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 4ed25f6 commit 43a82f8

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

test/parallel/test-sync-io-option.js

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

33
const assert = require('assert');
4-
const spawn = require('child_process').spawn;
5-
4+
const execFile = require('child_process').execFile;
65

76
if (process.argv[2] === 'child') {
87
setImmediate(function() {
@@ -14,34 +13,23 @@ if (process.argv[2] === 'child') {
1413
(function runTest(flags) {
1514
var execArgv = [flags.pop()];
1615
var args = [__filename, 'child'];
17-
var child = spawn(process.execPath, execArgv.concat(args));
18-
var stderr = '';
19-
20-
child.stdout.on('data', function(chunk) {
21-
throw new Error('UNREACHABLE');
22-
});
23-
24-
child.stderr.on('data', function(chunk) {
25-
stderr += chunk.toString();
26-
});
27-
28-
child.on('close', function() {
29-
var cntr1 = (stderr.match(/WARNING/g) || []).length;
30-
var cntr2 = (stderr.match(/fs\.readFileSync/g) || []).length;
31-
assert.equal(cntr1, cntr2);
32-
if (execArgv[0] === '--trace-sync-io') {
33-
// Prints 4 WARNINGS for --trace-sync-io. 1 for each sync call
34-
// inside readFileSync
35-
assert.equal(cntr1, 4);
36-
} else if (execArgv[0] === ' ') {
37-
assert.equal(cntr1, 0);
16+
var cntr = 0;
17+
args = execArgv.concat(args);
18+
if (!args[0]) args.shift();
19+
execFile(process.execPath, args, function(err, stdout, stderr) {
20+
assert.equal(err, null);
21+
assert.equal(stdout, '');
22+
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
23+
cntr++;
24+
if (args[0] === '--trace-sync-io') {
25+
assert.equal(cntr, 1);
26+
} else if (args[0] === __filename) {
27+
assert.equal(cntr, 0);
3828
} else {
3929
throw new Error('UNREACHABLE');
4030
}
41-
4231
if (flags.length > 0)
4332
setImmediate(runTest, flags);
4433
});
45-
}(['--trace-sync-io', ' ']));
34+
}(['--trace-sync-io', '']));
4635
}
47-

0 commit comments

Comments
 (0)