xref: /third_party/node/test/parallel/test-worker-vm-context-terminate.js
  • 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 vm = require('vm');
51cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Do not use isMainThread so that this test itself can be run inside a Worker.
81cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) {
91cb0ef41Sopenharmony_ci  process.env.HAS_STARTED_WORKER = 1;
101cb0ef41Sopenharmony_ci  const w = new Worker(__filename);
111cb0ef41Sopenharmony_ci  w.on('online', common.mustCall(() => {
121cb0ef41Sopenharmony_ci    setTimeout(() => w.terminate(), 50);
131cb0ef41Sopenharmony_ci  }));
141cb0ef41Sopenharmony_ci  w.on('error', common.mustNotCall());
151cb0ef41Sopenharmony_ci  w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));
161cb0ef41Sopenharmony_ci} else {
171cb0ef41Sopenharmony_ci  while (true)
181cb0ef41Sopenharmony_ci    vm.runInNewContext('');
191cb0ef41Sopenharmony_ci}
20

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