Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test-sync-io-option #1734

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions test/parallel/test-sync-io-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ if (process.argv[2] === 'child') {
var execArgv = [flags.pop()];
var args = [__filename, 'child'];
var child = spawn(process.execPath, execArgv.concat(args));
var cntr = 0;
var stderr = '';

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

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

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

Expand Down