forked from nodejs/quic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-quic-quicsession-openstream-pending.js
More file actions
56 lines (42 loc) · 1.37 KB
/
test-quic-quicsession-openstream-pending.js
File metadata and controls
56 lines (42 loc) · 1.37 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
// Flags: --no-warnings
'use strict';
const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');
// Test that opening a stream works even if the session isn’t ready yet.
const assert = require('assert');
const quic = require('quic');
const { key, cert, ca } = require('../common/quic');
const { once } = require('events');
const options = { key, cert, ca, alpn: 'meow' };
(async () => {
const server = quic.createSocket({ server: options });
const client = quic.createSocket({ client: options });
server.listen();
server.on('session', common.mustCall((session) => {
session.on('stream', common.mustCall(async (stream) => {
let data = '';
stream.setEncoding('utf8');
stream.on('data', (chunk) => data += chunk);
await once(stream, 'end');
assert.strictEqual(data, 'Hello!');
}));
}));
await once(server, 'ready');
const req = client.connect({
address: common.localhostIPv4,
port: server.endpoints[0].address.port
});
const stream = req.openStream({ halfOpen: true });
stream.end('Hello!');
assert.strictEqual(stream.pending, true);
await once(stream, 'ready');
assert.strictEqual(stream.pending, false);
await once(stream, 'close');
server.close();
client.close();
await Promise.allSettled([
once(server, 'close'),
once(client, 'close')
]);
})().then(common.mustCall());