xref: /third_party/node/test/parallel/test-worker-beforeexit-throw-exit.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Test that 'exit' is emitted if 'beforeExit' throws, both inside the Worker.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst workerData = new Uint8Array(new SharedArrayBuffer(2));
91cb0ef41Sopenharmony_ciconst w = new Worker(`
101cb0ef41Sopenharmony_ci  const { workerData } = require('worker_threads');
111cb0ef41Sopenharmony_ci  process.on('exit', () => {
121cb0ef41Sopenharmony_ci    workerData[0] = 100;
131cb0ef41Sopenharmony_ci  });
141cb0ef41Sopenharmony_ci  process.on('beforeExit', () => {
151cb0ef41Sopenharmony_ci    workerData[1] = 200;
161cb0ef41Sopenharmony_ci    throw new Error('banana');
171cb0ef41Sopenharmony_ci  });
181cb0ef41Sopenharmony_ci`, { eval: true, workerData });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciw.on('error', common.mustCall((err) => {
211cb0ef41Sopenharmony_ci  assert.strictEqual(err.message, 'banana');
221cb0ef41Sopenharmony_ci}));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciw.on('exit', common.mustCall((code) => {
251cb0ef41Sopenharmony_ci  assert.strictEqual(code, 1);
261cb0ef41Sopenharmony_ci  assert.strictEqual(workerData[0], 100);
271cb0ef41Sopenharmony_ci  assert.strictEqual(workerData[1], 200);
281cb0ef41Sopenharmony_ci}));
29

Indexes created Thu Nov 07 10:32:03 CST 2024