summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-spawnsync-timeout.js
blob: 38f22deef26ae75dce73400bfcc656d238462b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
const common = require('../common');
const assert = require('assert');

const spawnSync = require('child_process').spawnSync;

const TIMER = 200;
const SLEEP = common.platformTimeout(5000);

switch (process.argv[2]) {
  case 'child':
    setTimeout(function() {
      console.log('child fired');
      process.exit(1);
    }, SLEEP);
    break;
  default:
    const start = Date.now();
    const ret = spawnSync(process.execPath, [__filename, 'child'],
                        {timeout: TIMER});
    assert.strictEqual(ret.error.errno, 'ETIMEDOUT');
    const end = Date.now() - start;
    assert(end < SLEEP);
    assert(ret.status > 128 || ret.signal);
    break;
}