Skip to content

Instantly share code, notes, and snippets.

@eladb
Created March 13, 2012 15:23
Show Gist options
  • Save eladb/2029393 to your computer and use it in GitHub Desktop.
Save eladb/2029393 to your computer and use it in GitHub Desktop.
node.js test fails when pipes are not closed on Windows
require('child_process').spawn(process.execPath, ['grandchild']);
// exit after 500ms
setTimeout(function() { process.exit(1); }, 500);
// exit after 2s
setTimeout(function() { process.exit(0); }, 2000);
var spawn = require('child_process').spawn;
var assert = require('assert');
process.chdir(__dirname);
var start = Date.now();
var child = spawn(process.execPath, ['child']);
child.on('exit', function() {
var elapsed = Date.now() - start;
console.log('elapsed time to exit: %dms', elapsed);
assert.ok(elapsed < 2000, 'expecting exit event to be emitted after less than 2s since child exits after 500ms');
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment