Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 081e1a4

Browse files
oyydaddaleax
authored andcommitted
test: add tests for quic idleTimeout
It would be better to add a test to ensure that the timeout is greater than the triple PTO if we can get the PTO. PR-URL: #160 Reviewed-By: James M Snell <[email protected]>
1 parent 55c12a0 commit 081e1a4

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasQuic)
5+
common.skip('missing quic');
6+
7+
const assert = require('assert');
8+
const { createSocket } = require('quic');
9+
const fixtures = require('../common/fixtures');
10+
const key = fixtures.readKey('agent1-key.pem', 'binary');
11+
const cert = fixtures.readKey('agent1-cert.pem', 'binary');
12+
const ca = fixtures.readKey('ca1-cert.pem', 'binary');
13+
14+
const kServerName = 'agent2';
15+
const kALPN = 'zzz';
16+
// Allow error for 500 milliseconds more.
17+
const error = common.platformTimeout(500);
18+
const idleTimeout = common.platformTimeout(1000);
19+
20+
// Test client idle timeout.
21+
{
22+
let client;
23+
const server = createSocket({ port: 0 });
24+
server.listen({
25+
key,
26+
cert,
27+
ca,
28+
alpn: kALPN,
29+
});
30+
31+
server.on('session', common.mustCall());
32+
33+
server.on('ready', common.mustCall(() => {
34+
client = createSocket({
35+
port: 0,
36+
client: {
37+
key,
38+
cert,
39+
ca,
40+
alpn: kALPN,
41+
}
42+
});
43+
44+
const start = Date.now();
45+
46+
const clientSession = client.connect({
47+
address: 'localhost',
48+
port: server.address.port,
49+
servername: kServerName,
50+
idleTimeout,
51+
});
52+
53+
clientSession.on('close', common.mustCall(() => {
54+
client.close();
55+
server.close();
56+
assert(Date.now() - start < idleTimeout + error);
57+
}));
58+
}));
59+
}
60+
61+
// Test server idle timeout.
62+
{
63+
let client;
64+
let start;
65+
const server = createSocket({ port: 0 });
66+
server.listen({
67+
key,
68+
cert,
69+
ca,
70+
alpn: kALPN,
71+
idleTimeout,
72+
});
73+
74+
server.on('session', common.mustCall(() => {
75+
client.close();
76+
server.close();
77+
assert(Date.now() - start < idleTimeout + error);
78+
}));
79+
80+
server.on('ready', common.mustCall(() => {
81+
client = createSocket({
82+
port: 0,
83+
client: {
84+
key,
85+
cert,
86+
ca,
87+
alpn: kALPN,
88+
}
89+
});
90+
91+
92+
start = Date.now();
93+
const clientSession = client.connect({
94+
address: 'localhost',
95+
port: server.address.port,
96+
servername: kServerName,
97+
});
98+
99+
clientSession.on('close', common.mustCall());
100+
}));
101+
}

0 commit comments

Comments
 (0)