Browse Source

test: rewrite spawnsync test

The spawnsync test was written wrong, the timeout can never fire before
the sync process has returned, the delta is immaterial and times when
it was succeeding are not reliable cases.

Instead verify that the timeout doesn't fire while the sync process is
happening.
archived-io.js-v0.10
Timothy J Fontaine 11 years ago
parent
commit
58cc362251
  1. 24
      test/simple/test-child-process-spawnsync.js

24
test/simple/test-child-process-spawnsync.js

@ -27,30 +27,22 @@ var spawnSync = require('child_process').spawnSync;
var TIMER = 100;
var SLEEP = 1000;
var start = Date.now();
var timeout = 0;
setTimeout(function() {
console.log('timer fired');
timeout = Date.now();
timeout = process.hrtime(start);
assert.ok(stop, 'timer should not fire before process exits');
assert.strictEqual(timeout[0], 1, 'timer should take as long as sleep');
}, TIMER);
console.log('sleep started');
var start = process.hrtime();
var ret = spawnSync('sleep', ['1']);
console.log('sleep exited');
var stop = process.hrtime(start);
assert.strictEqual(ret.status, 0, 'exit status should be zero');
console.log('sleep exited', stop);
assert.strictEqual(stop[0], 1, 'sleep should not take longer or less than 1 second');
// Error test when command does not exist
var ret_err = spawnSync('command_does_not_exist');
assert.strictEqual(ret_err.error.code, 'ENOENT');
process.on('exit', function() {
assert.strictEqual(ret.status, 0);
var delta = Date.now() - start;
var expected_timeout = start + TIMER;
var tdlta = timeout - expected_timeout;
assert(delta > SLEEP);
assert(tdlta > TIMER && tdlta < SLEEP);
});

Loading…
Cancel
Save