镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit ab87282

Browse files
davidbenMylesBorins
authored andcommitted
test: fix flaky test-http2-create-client-connect
The first group of tests makes one more connection and leave the server alive for longer. Otherwise the test is just catching that the server has closed the socket, depending on timing. This does not quite make the test pass yet, however. There are some quirks with how the http2 code handles errors which actually affect 1.0.2 as well. PR-URL: #16130 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 2b25ad1 commit ab87282

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

‎test/parallel/test-http2-create-client-connect.js‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Tests http2.connect()
44

55
const common = require('../common');
6+
const Countdown = require('../common/countdown');
67
if (!common.hasCrypto)
78
common.skip('missing crypto');
89
const fixtures = require('../common/fixtures');
@@ -25,13 +26,12 @@ const URL = url.URL;
2526
[{ port: port, hostname: '127.0.0.1' }, { protocol: 'http:' }]
2627
];
2728

28-
let count = items.length;
29+
const serverClose = new Countdown(items.length + 1,
30+
() => setImmediate(() => server.close()));
2931

3032
const maybeClose = common.mustCall((client) => {
3133
client.destroy();
32-
if (--count === 0) {
33-
setImmediate(() => server.close());
34-
}
34+
serverClose.dec();
3535
}, items.length);
3636

3737
items.forEach((i) => {
@@ -42,7 +42,7 @@ const URL = url.URL;
4242

4343
// Will fail because protocol does not match the server.
4444
h2.connect({ port: port, protocol: 'https:' })
45-
.on('socketError', common.mustCall());
45+
.on('socketError', common.mustCall(() => serverClose.dec()));
4646
}));
4747
}
4848

@@ -70,13 +70,12 @@ const URL = url.URL;
7070
[{ port: port, hostname: '127.0.0.1', protocol: 'https:' }, opts]
7171
];
7272

73-
let count = items.length;
73+
const serverClose = new Countdown(items.length,
74+
() => setImmediate(() => server.close()));
7475

7576
const maybeClose = common.mustCall((client) => {
7677
client.destroy();
77-
if (--count === 0) {
78-
setImmediate(() => server.close());
79-
}
78+
serverClose.dec();
8079
}, items.length);
8180

8281
items.forEach((i) => {

0 commit comments

Comments
 (0)