Skip to content

Commit e487547

Browse files
committed
tests: start adding quic test server utilities
1 parent 79519d8 commit e487547

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

deps/ngtcp2/ngtcp2.gyp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@
268268
'EV_STANDALONE=1',
269269
],
270270
'conditions': [
271+
['OS==aix"', {
272+
# AIX does not support some of the networking features used in
273+
# the test server.
274+
'type': 'none', # Disable as executable on AIX
275+
}],
271276
['OS=="mac"', {
272277
'defines': [
273278
'__APPLE_USE_RFC_3542',
@@ -335,6 +340,11 @@
335340
'EV_STANDALONE=1',
336341
],
337342
'conditions': [
343+
['OS=="aix"', {
344+
# AIX does not support some of the networking features used in
345+
# the test client.
346+
'type': 'none', # Disable as executable on AIX
347+
}],
338348
['OS=="mac"', {
339349
'defines': [
340350
'__APPLE_USE_RFC_3542',

test/common/quic/test-server.mjs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { resolve } from 'node:path';
2+
import { spawn } from 'node:child_process';
3+
4+
export default class QuicTestServer {
5+
#pathToServer;
6+
#runningProcess;
7+
8+
constructor() {
9+
this.#pathToServer = resolve(process.execPath, '../ngtcp2_test_server');
10+
console.log(this.#pathToServer);
11+
}
12+
13+
help(options = { stdio: 'inherit' }) {
14+
const { promise, resolve, reject } = Promise.withResolvers();
15+
const proc = spawn(this.#pathToServer, ['--help'], options);
16+
proc.on('error', reject);
17+
proc.on('exit', (code, signal) => {
18+
if (code === 0) {
19+
resolve();
20+
} else {
21+
reject(new Error(`Process exited with code ${code} and signal ${signal}`));
22+
}
23+
});
24+
return promise;
25+
}
26+
27+
run(address, port, keyFile, certFile, options = { stdio: 'inherit' }) {
28+
const { promise, resolve, reject } = Promise.withResolvers();
29+
if (this.#runningProcess) {
30+
reject(new Error('Server is already running'));
31+
return promise;
32+
}
33+
const args = [
34+
address,
35+
port,
36+
keyFile,
37+
certFile,
38+
];
39+
this.#runningProcess = spawn(this.#pathToServer, args, options);
40+
this.#runningProcess.on('error', (err) => {
41+
this.#runningProcess = undefined;
42+
reject(err);
43+
});
44+
this.#runningProcess.on('exit', (code, signal) => {
45+
this.#runningProcess = undefined;
46+
if (code === 0) {
47+
resolve();
48+
} else {
49+
if (code === null && signal === 'SIGTERM') {
50+
// Normal termination due to stop() being called.
51+
resolve();
52+
return;
53+
}
54+
reject(new Error(`Process exited with code ${code} and signal ${signal}`));
55+
}
56+
});
57+
return promise;
58+
}
59+
60+
stop() {
61+
if (this.#runningProcess) {
62+
this.#runningProcess.kill();
63+
this.#runningProcess = undefined;
64+
}
65+
}
66+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Flags: --experimental-quic
2+
import { hasQuic, isAIX, skip } from '../common/index.mjs';
3+
4+
if (!hasQuic) {
5+
skip('QUIC support is not enabled');
6+
}
7+
if (isAIX) {
8+
skip('QUIC third-party tests are disabled on AIX');
9+
}
10+
11+
const { default: QuicTestServer } = await import('../common/quic/test-server.mjs');
12+
const fixtures = await import('../common/fixtures.mjs');
13+
14+
const server = new QuicTestServer();
15+
const fixturesPath = fixtures.path();
16+
17+
// If this completes without throwing, the test passes.
18+
await server.help({ stdio: 'ignore' });
19+
20+
setTimeout(() => {
21+
server.stop();
22+
}, 100);
23+
24+
await server.run('localhost', '12345',
25+
`${fixturesPath}/keys/agent1-key.pem`,
26+
`${fixturesPath}/keys/agent1-cert.pem`,
27+
{ stdio: 'inherit' });

0 commit comments

Comments
 (0)