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

Commit

Permalink
test: add tests for quic idleTimeout
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
oyyd authored and jasnell committed Oct 9, 2019
1 parent d9ee6ab commit 81e9492
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions test/parallel/test-quic-idle-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

const assert = require('assert');
const { createSocket } = 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 kServerName = 'agent2';
const kALPN = 'zzz';
// Allow error for 500 milliseconds more.
const error = common.platformTimeout(500);
const idleTimeout = common.platformTimeout(1000);

// Test client idle timeout.
{
let client;
const server = createSocket({ port: 0 });
server.listen({
key,
cert,
ca,
alpn: kALPN,
});

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

server.on('ready', common.mustCall(() => {
client = createSocket({
port: 0,
client: {
key,
cert,
ca,
alpn: kALPN,
}
});

const start = Date.now();

const clientSession = client.connect({
address: 'localhost',
port: server.address.port,
servername: kServerName,
idleTimeout,
});

clientSession.on('close', common.mustCall(() => {
client.close();
server.close();
assert(Date.now() - start < idleTimeout + error);
}));
}));
}

// Test server idle timeout.
{
let client;
let start;
const server = createSocket({ port: 0 });
server.listen({
key,
cert,
ca,
alpn: kALPN,
idleTimeout,
});

server.on('session', common.mustCall(() => {
client.close();
server.close();
assert(Date.now() - start < idleTimeout + error);
}));

server.on('ready', common.mustCall(() => {
client = createSocket({
port: 0,
client: {
key,
cert,
ca,
alpn: kALPN,
}
});


start = Date.now();
const clientSession = client.connect({
address: 'localhost',
port: server.address.port,
servername: kServerName,
});

clientSession.on('close', common.mustCall());
}));
}

0 comments on commit 81e9492

Please sign in to comment.