Skip to content

Commit 0f36493

Browse files
committedApr 9, 2025·
test: fixed request-response handling
1 parent 20ba444 commit 0f36493

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
 

‎test/parallel/test-http2-session-graceful-close.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,17 @@ const assert = require('assert');
77
const h2 = require('http2');
88

99
const server = h2.createServer();
10-
let response;
10+
let session;
1111

12-
server.on('session', common.mustCall(function(session) {
13-
session.on('stream', common.mustCall(function (stream) {
14-
response.end();
15-
session.close();
16-
}));
17-
session.on('close', common.mustCall(function() {
18-
server.close();
19-
}));
12+
server.on('session', common.mustCall(function(s) {
13+
session = s;
14+
session.on('close', common.mustCall(function() {
15+
server.close();
16+
}));
2017
}));
2118

2219
server.listen(0, common.mustCall(function() {
2320
const port = server.address().port;
24-
server.once('request', common.mustCall(function (request, resp) {
25-
response = resp;
26-
}));
2721

2822
const url = `http://localhost:${port}`;
2923
const client = h2.connect(url, common.mustCall(function() {
@@ -45,3 +39,10 @@ server.listen(0, common.mustCall(function() {
4539
}));
4640
client.on('goaway', common.mustCallAtLeast(1));
4741
}));
42+
43+
server.once('request', common.mustCall(function(request, response) {
44+
response.on('finish', common.mustCall(function() {
45+
session.close();
46+
}));
47+
response.end();
48+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.