summaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-vm-context-terminate.js
blob: 23b58ba4db14d5781e27e71d9675f0d4da150617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
const common = require('../common');
const assert = require('assert');
const vm = require('vm');
const { Worker } = require('worker_threads');

// Do not use isMainThread so that this test itself can be run inside a Worker.
if (!process.env.HAS_STARTED_WORKER) {
  process.env.HAS_STARTED_WORKER = 1;
  const w = new Worker(__filename);
  w.on('online', common.mustCall(() => {
    setTimeout(() => w.terminate(), 50);
  }));
  w.on('error', common.mustNotCall());
  w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));
} else {
  while (true)
    vm.runInNewContext('');
}