From 867631986f5cd8950caf706ee92fc2a8ee3d4c0f Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 19 May 2015 10:22:37 +0200 Subject: [PATCH] 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: https://github.com/nodejs/io.js/pull/1734 Reviewed-By: Trevor Norris --- test/parallel/test-sync-io-option.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-sync-io-option.js b/test/parallel/test-sync-io-option.js index 390710d265e7bf..2dc0bf4cc1fb96 100644 --- a/test/parallel/test-sync-io-option.js +++ b/test/parallel/test-sync-io-option.js @@ -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');