11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/947
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst cp = require('child_process');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
81cb0ef41Sopenharmony_ci  process.on('message', common.mustCall((msg) => {
91cb0ef41Sopenharmony_ci    assert.strictEqual(msg, 'go');
101cb0ef41Sopenharmony_ci    // The following console.log is an integral part
111cb0ef41Sopenharmony_ci    // of the test. If this regress, this call will
121cb0ef41Sopenharmony_ci    // cause the process to exit with 1
131cb0ef41Sopenharmony_ci    console.log('logging should not cause a crash');
141cb0ef41Sopenharmony_ci    process.disconnect();
151cb0ef41Sopenharmony_ci  }));
161cb0ef41Sopenharmony_ci} else {
171cb0ef41Sopenharmony_ci  // Passing '--inspect', '--inspect-brk' to child.spawn enables
181cb0ef41Sopenharmony_ci  // the debugger. This test was added to help debug the fork-based
191cb0ef41Sopenharmony_ci  // test with the same name.
201cb0ef41Sopenharmony_ci  const child = cp.spawn(process.execPath, [__filename, 'child'], {
211cb0ef41Sopenharmony_ci    stdio: ['pipe', 'pipe', 'pipe', 'ipc']
221cb0ef41Sopenharmony_ci  });
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  child.on('close', common.mustCall((exitCode, signal) => {
251cb0ef41Sopenharmony_ci    assert.strictEqual(exitCode, 0);
261cb0ef41Sopenharmony_ci    assert.strictEqual(signal, null);
271cb0ef41Sopenharmony_ci  }));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  child.stdout.destroy();
301cb0ef41Sopenharmony_ci  child.send('go');
311cb0ef41Sopenharmony_ci}
32