Skip to content

Commit 8676319

Browse files
santigimenobrendanashworth
authored andcommitted
test: fix test-sync-io-option
Wait for all the data to be available in stderr before checking its contents. In FreeBSD this was failing because stderr data was being emitted in multiple chunks. 4 WARNINGS are printed instead of 2 for each sync call inside readFileSync. require('fs') does not print any trace. PR-URL: #1734 Reviewed-By: Trevor Norris <[email protected]>
1 parent f29762f commit 8676319

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@ if (process.argv[2] === 'child') {
1515
var execArgv = [flags.pop()];
1616
var args = [__filename, 'child'];
1717
var child = spawn(process.execPath, execArgv.concat(args));
18-
var cntr = 0;
18+
var stderr = '';
1919

2020
child.stdout.on('data', function(chunk) {
2121
throw new Error('UNREACHABLE');
2222
});
2323

2424
child.stderr.on('data', function(chunk) {
25-
// Prints twice for --trace-sync-io. First for the require() and second
26-
// for the fs operation.
27-
if (/^WARNING[\s\S]*fs\.readFileSync/.test(chunk.toString()))
28-
cntr++;
25+
stderr += chunk.toString();
2926
});
3027

31-
child.on('exit', function() {
32-
if (execArgv[0] === '--trace-sync-io')
33-
assert.equal(cntr, 2);
34-
else if (execArgv[0] === ' ')
35-
assert.equal(cntr, 0);
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);
3638
else
3739
throw new Error('UNREACHABLE');
3840

0 commit comments

Comments
 (0)