Skip to content

Commit f37498d

Browse files
committed
quic: don't use setTimeout in the tests
Signed-off-by: Efe Karasakal <hi@efe.dev>
1 parent b1f7e9e commit f37498d

1 file changed

Lines changed: 25 additions & 27 deletions

File tree

‎test/parallel/test-quic-session-close-reason-truncation.mjs‎

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { hasQuic, skip, mustCall } from '../common/index.mjs';
66
import assert from 'node:assert';
7-
import { setTimeout } from 'node:timers/promises';
87

98
if (!hasQuic) {
109
skip('QUIC is not enabled');
@@ -18,81 +17,75 @@ const kMaxReasonLength = 256;
1817
{
1918
const reason = 'a'.repeat(kMaxReasonLength + 1);
2019
const expectedReason = reason.slice(0, kMaxReasonLength);
21-
const serverDone = Promise.withResolvers();
20+
const serverSessionReady = Promise.withResolvers();
2221

2322
const serverEndpoint = await listen(mustCall(async (serverSession) => {
2423
serverSession.onerror = mustCall((error) => {
2524
assert.strictEqual(error.reason, expectedReason);
2625
});
27-
await assert.rejects(serverSession.closed, {
28-
code: 'ERR_QUIC_APPLICATION_ERROR',
29-
reason: expectedReason,
30-
});
31-
serverDone.resolve();
26+
await serverSession.opened;
27+
serverSessionReady.resolve(serverSession);
3228
}));
3329

3430
const clientSession = await connect(serverEndpoint.address, {
3531
reuseEndpoint: false,
3632
});
3733
await clientSession.opened;
38-
await setTimeout(100);
34+
const serverSession = await serverSessionReady.promise;
3935
await clientSession.close({
4036
code: 1n,
4137
type: 'application',
4238
reason,
4339
});
4440

45-
await serverDone.promise;
41+
await assert.rejects(serverSession.closed, {
42+
code: 'ERR_QUIC_APPLICATION_ERROR',
43+
reason: expectedReason,
44+
});
4645
await serverEndpoint.close();
4746
}
4847

4948
// Client close where truncating at the byte limit would split a UTF-8 sequence.
5049
{
5150
const prefix = 'a'.repeat(kMaxReasonLength - 1);
5251
const reason = `${prefix}€`;
53-
const serverDone = Promise.withResolvers();
52+
const serverSessionReady = Promise.withResolvers();
5453

5554
const serverEndpoint = await listen(mustCall(async (serverSession) => {
5655
serverSession.onerror = mustCall((error) => {
5756
assert.strictEqual(error.reason, prefix);
5857
});
59-
await assert.rejects(serverSession.closed, {
60-
code: 'ERR_QUIC_APPLICATION_ERROR',
61-
reason: prefix,
62-
});
63-
serverDone.resolve();
58+
await serverSession.opened;
59+
serverSessionReady.resolve(serverSession);
6460
}));
6561

6662
const clientSession = await connect(serverEndpoint.address, {
6763
reuseEndpoint: false,
6864
});
6965
await clientSession.opened;
70-
await setTimeout(100);
66+
const serverSession = await serverSessionReady.promise;
7167
await clientSession.close({
7268
code: 2n,
7369
type: 'application',
7470
reason,
7571
});
7672

77-
await serverDone.promise;
73+
await assert.rejects(serverSession.closed, {
74+
code: 'ERR_QUIC_APPLICATION_ERROR',
75+
reason: prefix,
76+
});
7877
await serverEndpoint.close();
7978
}
8079

8180
// Server close exercises the server-specific CONNECTION_CLOSE packet path.
8281
{
8382
const reason = 's'.repeat(kMaxReasonLength + 1);
8483
const expectedReason = reason.slice(0, kMaxReasonLength);
85-
const serverDone = Promise.withResolvers();
84+
const serverSessionReady = Promise.withResolvers();
8685

8786
const serverEndpoint = await listen(mustCall(async (serverSession) => {
8887
await serverSession.opened;
89-
await setTimeout(100);
90-
await serverSession.close({
91-
code: 3n,
92-
type: 'application',
93-
reason,
94-
});
95-
serverDone.resolve();
88+
serverSessionReady.resolve(serverSession);
9689
}));
9790

9891
const clientSession = await connect(serverEndpoint.address, {
@@ -102,11 +95,16 @@ const kMaxReasonLength = 256;
10295
}),
10396
});
10497
await clientSession.opened;
98+
const serverSession = await serverSessionReady.promise;
99+
await serverSession.close({
100+
code: 3n,
101+
type: 'application',
102+
reason,
103+
});
104+
105105
await assert.rejects(clientSession.closed, {
106106
code: 'ERR_QUIC_APPLICATION_ERROR',
107107
reason: expectedReason,
108108
});
109-
110-
await serverDone.promise;
111109
await serverEndpoint.close();
112110
}

0 commit comments

Comments
 (0)