This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This resolves the situation in which `openStream()` is called before the underlying native `QuicSession` handle exists. Fixes: #181 PR-URL: #187 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
3 changed files
with
145 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'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 fixtures = require('../common/fixtures'); | ||
const key = fixtures.readKey('agent1-key.pem', 'binary'); | ||
const cert = fixtures.readKey('agent1-cert.pem', 'binary'); | ||
const ca = fixtures.readKey('ca1-cert.pem', 'binary'); | ||
|
||
const server = quic.createSocket({ port: 0, validateAddress: true }); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
rejectUnauthorized: false, | ||
maxCryptoBuffer: 4096, | ||
alpn: 'meow', | ||
maxStreamsUni: 100 | ||
}); | ||
|
||
server.on('session', common.mustCall((session) => { | ||
session.on('stream', common.mustCall((stream) => { | ||
let data = ''; | ||
stream.setEncoding('utf8'); | ||
stream.on('data', (chunk) => data += chunk); | ||
stream.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, 'Hello!'); | ||
session.close(); | ||
server.close(); | ||
})); | ||
})); | ||
|
||
session.on('close', common.mustCall()); | ||
})); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const client = quic.createSocket({ | ||
port: 0, | ||
client: { | ||
key, | ||
cert, | ||
ca, | ||
alpn: 'meow' | ||
} | ||
}); | ||
|
||
const req = client.connect({ | ||
address: 'localhost', | ||
port: server.address.port | ||
}); | ||
|
||
const stream = req.openStream({ halfOpen: true }); | ||
stream.end('Hello!'); | ||
|
||
assert.strictEqual(stream.pending, true); | ||
stream.on('ready', common.mustCall(() => { | ||
assert.strictEqual(stream.pending, false); | ||
})); | ||
|
||
req.on('close', common.mustCall(() => client.close())); | ||
})); | ||
|
||
server.on('close', common.mustCall()); |