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

Commit

Permalink
quic: fixup test for server busy, other fixes
Browse files Browse the repository at this point in the history
PR-URL: #85
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
jasnell committed Aug 23, 2019
1 parent e57681b commit 89ad55d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
12 changes: 6 additions & 6 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function onSessionClose(code, family) {
// session will enter the closing period, after which it will
// be destroyed either when the idle timeout expires, the
// QuicSession is silently closed, or destroy is called.
this[owner_symbol][kClose](code, family);
this[owner_symbol][kClose](family, code);
}

// This callback is invoked at the start of the TLS handshake to provide
Expand Down Expand Up @@ -1342,7 +1342,7 @@ class QuicSession extends EventEmitter {
supportedVersions);
}

[kClose](code, family) {
[kClose](family, code) {
// Immediate close has been initiated for the session. Any
// still open QuicStreams must be abandoned and shutdown
// with RESET_STREAM and STOP_SENDING frames transmitted
Expand All @@ -1360,13 +1360,13 @@ class QuicSession extends EventEmitter {

// Shutdown all of the remaining streams
for (const stream of this.#streams.values())
stream[kClose](code, family);
stream[kClose](family, code);

// By this point, all necessary RESET_STREAM and
// STOP_SENDING frames ought to have been sent,
// so now we just trigger sending of the
// CONNECTION_CLOSE frame.
this[kHandle].close(code, family);
this[kHandle].close(family, code);
}

[kStreamClose](id, code) {
Expand Down Expand Up @@ -2101,7 +2101,7 @@ class QuicStream extends Duplex {
this.read();
}

[kClose](code, family) {
[kClose](family, code) {
// Trigger the abrupt shutdown of the stream. If the stream is
// already no-longer readable or writable, this does nothing. If
// the stream is readable or writable, then the abort event will
Expand Down Expand Up @@ -2262,7 +2262,7 @@ class QuicStream extends Duplex {
}

close(code) {
this[kClose](code, QUIC_ERROR_APPLICATION);
this[kClose](QUIC_ERROR_APPLICATION, code);
}

get session() {
Expand Down
42 changes: 17 additions & 25 deletions test/parallel/test-quic-serverbusy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

// TODO(@jasnell): Marking a server as busy will cause all new
// connection attempts to fail with a SERVER_BUSY CONNECTION_CLOSE.
// Unfortunately, however, ngtcp2 does not yet support writing a
// CONNECTION_CLOSE in an initial packet as required by the
// specification so we can't enable this yet. The basic mechanism
// has been implemented but we can't expose it yet.

common.skip('setServerBusy is not yet fully implemented.');

const assert = require('assert');
const fixtures = require('../common/fixtures');
const key = fixtures.readKey('agent1-key.pem', 'binary');
Expand Down Expand Up @@ -48,7 +39,10 @@ server.on('busy', common.mustCall((busy) => {
server.setServerBusy();
server.listen();

server.on('session', common.mustNotCall());
server.on('session', common.mustCall((session) => {
session.on('stream', common.mustNotCall());
session.on('close', common.mustCall());
}));

server.on('ready', common.mustCall(() => {
debug('Server is listening on port %d', server.address.port);
Expand All @@ -57,26 +51,24 @@ server.on('ready', common.mustCall(() => {
client: { key, cert, ca, alpn: kALPN }
});

client.connect({
client.on('close', common.mustCall());

const req = client.connect({
address: 'localhost',
port: server.address.port,
});

// The client session is going to be destroyed before
// the handshake can complete so the secure event will
// never emit.
req.on('secure', common.mustNotCall());

req.on('close', common.mustCall(() => {
server.close();
client.close();
}));
}));

server.on('listening', common.mustCall());

server.on('close', () => {
debug('Server closing. Duration', server.duration);
debug(' Bound duration:',
server.boundDuration);
debug(' Listen duration:',
server.listenDuration);
debug(' Bytes Sent/Received: %d/%d',
server.bytesSent,
server.bytesReceived);
debug(' Packets Sent/Received: %d/%d',
server.packetsSent,
server.packetsReceived);
debug(' Sessions:', server.serverSessions);
});
server.on('close', common.mustCall());

0 comments on commit 89ad55d

Please sign in to comment.