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.
test: add tests for quic
idleTimeout
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
Showing
1 changed file
with
101 additions
and
0 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
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()); | ||
})); | ||
} |