Skip to content

Commit 2bb0fb7

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.
1 parent 2c686fd commit 2bb0fb7

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

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

Lines changed: 12 additions & 25 deletions
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,22 @@ 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);
16+
var cntr = 0;
17+
args = execArgv.concat(args);
18+
execFile(process.execPath, args, function(err, stdout, stderr) {
19+
assert.equal(err, null);
20+
assert.equal(stdout, '');
21+
if (/^WARNING[\s\S]*fs\.readFileSync/.test(stderr))
22+
cntr++;
3223
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);
24+
assert.equal(cntr, 1);
25+
} else if (execArgv[0] === '--trace-deprecation') {
26+
assert.equal(cntr, 0);
3827
} else {
3928
throw new Error('UNREACHABLE');
4029
}
41-
4230
if (flags.length > 0)
4331
setImmediate(runTest, flags);
4432
});
45-
}(['--trace-sync-io', ' ']));
33+
}(['--trace-sync-io', '--trace-deprecation']));
4634
}
47-

0 commit comments

Comments
 (0)