forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-quic-client-empty-preferred-address.js
More file actions
57 lines (43 loc) · 1.44 KB
/
test-quic-client-empty-preferred-address.js
File metadata and controls
57 lines (43 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Flags: --no-warnings
'use strict';
// This test ensures that when we don't define `preferredAddress`
// on the server while the `preferredAddressPolicy` on the client
// is `accept`, it works as expected.
const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');
const assert = require('assert');
const { key, cert, ca } = require('../common/quic');
const { createQuicSocket } = require('net');
const { once } = require('events');
(async () => {
const server = createQuicSocket();
let client;
const options = { key, cert, ca, alpn: 'zzz' };
server.listen(options);
server.on('session', common.mustCall((serverSession) => {
serverSession.on('stream', common.mustCall(async (stream) => {
stream.on('data', common.mustCall((data) => {
assert.strictEqual(data.toString('utf8'), 'hello');
}));
await once(stream, 'end');
stream.close();
client.close();
server.close();
}));
}));
await once(server, 'ready');
client = createQuicSocket({ client: options });
const clientSession = client.connect({
address: common.localhostIPv4,
port: server.endpoints[0].address.port,
preferredAddressPolicy: 'accept',
});
await once(clientSession, 'secure');
const stream = clientSession.openStream();
stream.end('hello');
await Promise.all([
once(stream, 'close'),
once(client, 'close'),
once(server, 'close')]);
})().then(common.mustCall());