1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const assert = require('assert'); 7const http2 = require('http2'); 8const { Duplex } = require('stream'); 9const { Worker, workerData } = require('worker_threads'); 10 11// Tests the interaction between terminating a Worker thread and running 12// the native SetImmediate queue, which may attempt to perform multiple 13// calls into JS even though one already terminates the Worker. 14 15if (!workerData) { 16 const counter = new Int32Array(new SharedArrayBuffer(4)); 17 const worker = new Worker(__filename, { workerData: { counter } }); 18 worker.on('exit', common.mustCall(() => { 19 assert.strictEqual(counter[0], 1); 20 })); 21} else { 22 const { counter } = workerData; 23 24 // Start two HTTP/2 connections. This will trigger write()s call from inside 25 // the SetImmediate queue. 26 for (let i = 0; i < 2; i++) { 27 http2.connect('http://localhost', { 28 createConnection() { 29 return new Duplex({ 30 write(chunk, enc, cb) { 31 Atomics.add(counter, 0, 1); 32 process.exit(); 33 }, 34 read() { } 35 }); 36 } 37 }); 38 } 39} 40