Skip to content

Commit cf200b5

Browse files
add test
1 parent d55ddfc commit cf200b5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto)
4+
common.skip('missing crypto');
5+
const http2 = require('http2');
6+
const makeDuplexPair = require('../common/duplexpair');
7+
const { Worker, isMainThread, parentPort } = require('worker_threads');
8+
9+
// This test ensures that workers can be terminated without error while
10+
// stream activity is ongoing, in particular the C++ function
11+
// ReportWritesToJSStreamListener::OnStreamAfterReqFinished.
12+
13+
if (isMainThread) {
14+
const sab = new SharedArrayBuffer(4);
15+
const terminate = new Int32Array(sab);
16+
17+
const w = new Worker(__filename);
18+
w.postMessage(sab);
19+
process.nextTick(() => {
20+
Atomics.wait(terminate, 0, 0);
21+
setImmediate(() => w.terminate());
22+
});
23+
return;
24+
}
25+
26+
parentPort.on('message', (sab) => {
27+
const terminate = new Int32Array(sab);
28+
const server = http2.createServer();
29+
let i = 0;
30+
server.on('stream', (stream, headers) => {
31+
if (i === 1) {
32+
Atomics.store(terminate, 0, 1);
33+
Atomics.notify(terminate, 0, 1);
34+
}
35+
i++;
36+
37+
stream.end('');
38+
});
39+
40+
const { clientSide, serverSide } = makeDuplexPair();
41+
server.emit('connection', serverSide);
42+
43+
const client = http2.connect('http://localhost:80', {
44+
createConnection: () => clientSide,
45+
});
46+
47+
function makeReq() {
48+
for (let i = 0; i < 3; i++) {
49+
client.request().end();
50+
}
51+
setImmediate(makeReq);
52+
}
53+
makeReq();
54+
55+
});

0 commit comments

Comments
 (0)