Browse Source

test: speed up test-child-process-spawnsync.js

There's a bunch of stuff in test-child-process-spawnsync.js that seems
designed to test that it is in fact blocking/synchronous. However, that
code really just tests the OS sleep command. Change `sleep 1` to `sleep
0` and shave about one second off the test run.`

We check the return status to confirm the command is successful. The
tests in this file in general would not work if spawnSync() were
asynchronous. That includes this one, as a return status would not be
available if the command where asynchronous.

PR-URL: https://github.com/nodejs/node/pull/2542
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v4.0.0-rc
Rich Trott 10 years ago
parent
commit
fffa4c2528
  1. 17
      test/parallel/test-child-process-spawnsync.js

17
test/parallel/test-child-process-spawnsync.js

@ -4,21 +4,10 @@ var assert = require('assert');
var spawnSync = require('child_process').spawnSync; var spawnSync = require('child_process').spawnSync;
var TIMER = 100; // Echo does different things on Windows and Unix, but in both cases, it does
var SLEEP = 1000; // more-or-less nothing if there are no parameters
var ret = spawnSync('sleep', ['0']);
setTimeout(function() {
assert.ok(stop, 'timer should not fire before process exits');
}, TIMER);
console.log('sleep started');
var start = process.hrtime();
var ret = spawnSync('sleep', ['1']);
var stop = process.hrtime(start);
assert.strictEqual(ret.status, 0, 'exit status should be zero'); 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 // Error test when command does not exist
var ret_err = spawnSync('command_does_not_exist', ['bar']).error; var ret_err = spawnSync('command_does_not_exist', ['bar']).error;

Loading…
Cancel
Save