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

test: add tests for quic idleTimeout #160

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}));
}