11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst http2 = require('http2'); 81cb0ef41Sopenharmony_ciconst { Duplex } = require('stream'); 91cb0ef41Sopenharmony_ciconst { Worker, workerData } = require('worker_threads'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Tests the interaction between terminating a Worker thread and running 121cb0ef41Sopenharmony_ci// the native SetImmediate queue, which may attempt to perform multiple 131cb0ef41Sopenharmony_ci// calls into JS even though one already terminates the Worker. 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciif (!workerData) { 161cb0ef41Sopenharmony_ci const counter = new Int32Array(new SharedArrayBuffer(4)); 171cb0ef41Sopenharmony_ci const worker = new Worker(__filename, { workerData: { counter } }); 181cb0ef41Sopenharmony_ci worker.on('exit', common.mustCall(() => { 191cb0ef41Sopenharmony_ci assert.strictEqual(counter[0], 1); 201cb0ef41Sopenharmony_ci })); 211cb0ef41Sopenharmony_ci} else { 221cb0ef41Sopenharmony_ci const { counter } = workerData; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci // Start two HTTP/2 connections. This will trigger write()s call from inside 251cb0ef41Sopenharmony_ci // the SetImmediate queue. 261cb0ef41Sopenharmony_ci for (let i = 0; i < 2; i++) { 271cb0ef41Sopenharmony_ci http2.connect('http://localhost', { 281cb0ef41Sopenharmony_ci createConnection() { 291cb0ef41Sopenharmony_ci return new Duplex({ 301cb0ef41Sopenharmony_ci write(chunk, enc, cb) { 311cb0ef41Sopenharmony_ci Atomics.add(counter, 0, 1); 321cb0ef41Sopenharmony_ci process.exit(); 331cb0ef41Sopenharmony_ci }, 341cb0ef41Sopenharmony_ci read() { } 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci} 40