11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 51cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Test that 'exit' events for Workers are not received when the main thread 81cb0ef41Sopenharmony_ci// terminates itself through process.exit(). 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciif (process.argv[2] !== 'child') { 111cb0ef41Sopenharmony_ci const { 121cb0ef41Sopenharmony_ci stdout, stderr, status 131cb0ef41Sopenharmony_ci } = spawnSync(process.execPath, [__filename, 'child'], { encoding: 'utf8' }); 141cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 151cb0ef41Sopenharmony_ci assert.strictEqual(stdout, ''); 161cb0ef41Sopenharmony_ci assert.strictEqual(status, 0); 171cb0ef41Sopenharmony_ci} else { 181cb0ef41Sopenharmony_ci const nestedWorker = new Worker('setInterval(() => {}, 100)', { eval: true }); 191cb0ef41Sopenharmony_ci // This console.log() should never fire. 201cb0ef41Sopenharmony_ci nestedWorker.on('exit', () => console.log('exit event received')); 211cb0ef41Sopenharmony_ci nestedWorker.on('online', () => process.exit()); 221cb0ef41Sopenharmony_ci} 23