summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-send-after-close.js
blob: 4e26d1261866a0b1a384b6da98ab552e92dbe7e6 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fixtures = require('../common/fixtures');

const fixture = fixtures.path('empty.js');
const child = cp.fork(fixture);

child.on('close', common.mustCall((code, signal) => {
  assert.strictEqual(code, 0);
  assert.strictEqual(signal, null);

  const testError = common.expectsError({
    type: Error,
    message: 'Channel closed',
    code: 'ERR_IPC_CHANNEL_CLOSED'
  }, 2);

  child.on('error', testError);

  {
    const result = child.send('ping');
    assert.strictEqual(result, false);
  }

  {
    const result = child.send('pong', testError);
    assert.strictEqual(result, false);
  }
}));