11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst cp = require('child_process'); 51cb0ef41Sopenharmony_ciconst NUM_MESSAGES = 10; 61cb0ef41Sopenharmony_ciconst values = []; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cifor (let i = 0; i < NUM_MESSAGES; ++i) { 91cb0ef41Sopenharmony_ci values[i] = i; 101cb0ef41Sopenharmony_ci} 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 131cb0ef41Sopenharmony_ci const received = values.map(() => { return false; }); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci process.on('uncaughtException', common.mustCall((err) => { 161cb0ef41Sopenharmony_ci received[err] = true; 171cb0ef41Sopenharmony_ci const done = received.every((element) => { return element === true; }); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci if (done) 201cb0ef41Sopenharmony_ci process.disconnect(); 211cb0ef41Sopenharmony_ci }, NUM_MESSAGES)); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci process.on('message', (msg) => { 241cb0ef41Sopenharmony_ci // If messages are handled synchronously, throwing should break the IPC 251cb0ef41Sopenharmony_ci // message processing. 261cb0ef41Sopenharmony_ci throw msg; 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci process.send('ready'); 301cb0ef41Sopenharmony_ci} else { 311cb0ef41Sopenharmony_ci const child = cp.fork(__filename, ['child']); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci child.on('message', common.mustCall((msg) => { 341cb0ef41Sopenharmony_ci assert.strictEqual(msg, 'ready'); 351cb0ef41Sopenharmony_ci values.forEach((value) => { 361cb0ef41Sopenharmony_ci child.send(value); 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci })); 391cb0ef41Sopenharmony_ci} 40