summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-fork-close.js
blob: cec3c88f0fa11ce38b92c828a9737949fde29037 (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
27
28
29
30
31
32
33
34
35
36
'use strict';
const assert = require('assert');
const common = require('../common');
const fork = require('child_process').fork;

var cp = fork(common.fixturesDir + '/child-process-message-and-exit.js');

let gotMessage = false;
let gotExit = false;
let gotClose = false;

cp.on('message', function(message) {
  assert(!gotMessage);
  assert(!gotClose);
  assert.strictEqual(message, 'hello');
  gotMessage = true;
});

cp.on('exit', function() {
  assert(!gotExit);
  assert(!gotClose);
  gotExit = true;
});

cp.on('close', function() {
  assert(gotMessage);
  assert(gotExit);
  assert(!gotClose);
  gotClose = true;
});

process.on('exit', function() {
  assert(gotMessage);
  assert(gotExit);
  assert(gotClose);
});