Test more settings with Autobahn
This commit is contained in:
parent
d9a6b1010f
commit
c4cddb9477
@ -1,74 +1,81 @@
|
|||||||
/* Test server for autobahn, run with ASAN. /exit route shuts down. */
|
/* Test servers for autobahn, run with ASAN. /exit route shuts down everything */
|
||||||
|
|
||||||
const uWS = require('../dist/uws.js');
|
const uWS = require('../dist/uws.js');
|
||||||
let listenSocket, listenSocketSSL;
|
|
||||||
|
|
||||||
/* todo: A good idea is to test compression 1 for non-SSL and 2 for SSL */
|
/* Keep track of all apps */
|
||||||
/* or really just test more than twice */
|
let apps = [];
|
||||||
|
let closing = false;
|
||||||
|
|
||||||
/* Shared, among SSL and non-SSL, behavior of WebSockets */
|
function listenWithSettings(settings) {
|
||||||
const wsBehavior = {
|
/* These are our shared SSL options */
|
||||||
/* Options */
|
let sslOptions = {
|
||||||
compression: 2,
|
key_file_name: 'misc/key.pem',
|
||||||
maxPayloadLength: 16 * 1024 * 1024,
|
cert_file_name: 'misc/cert.pem',
|
||||||
idleTimeout: 60,
|
passphrase: '1234'
|
||||||
/* Handlers */
|
};
|
||||||
open: (ws, req) => {
|
|
||||||
console.log('A WebSocket connected via URL: ' + req.getUrl() + '!');
|
|
||||||
},
|
|
||||||
message: (ws, message, isBinary) => {
|
|
||||||
ws.send(message, isBinary);
|
|
||||||
},
|
|
||||||
drain: (ws) => {
|
|
||||||
console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
|
|
||||||
},
|
|
||||||
close: (ws, code, message) => {
|
|
||||||
console.log('WebSocket closed');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The SSL test server is on port 9002 */
|
/* Create the app */
|
||||||
const sslApp = uWS.SSLApp({
|
let app = settings.ssl ? uWS.App(sslOptions) : uWS.SSLApp(sslOptions);
|
||||||
key_file_name: 'misc/key.pem',
|
|
||||||
cert_file_name: 'misc/cert.pem',
|
|
||||||
passphrase: '1234'
|
|
||||||
}).ws('/*', wsBehavior).any('/exit', (res, req) => {
|
|
||||||
/* Stop listening on both SSL and non-SSL */
|
|
||||||
if (listenSocket) {
|
|
||||||
uWS.us_listen_socket_close(listenSocket);
|
|
||||||
uWS.us_listen_socket_close(listenSocketSSL);
|
|
||||||
listenSocket = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close this connection */
|
/* Attach our behavior from settings */
|
||||||
res.close();
|
app.ws('/*', {
|
||||||
}).listen(9002, (token) => {
|
compression: settings.compression,
|
||||||
if (token) {
|
maxPayloadLength: 16 * 1024 * 1024,
|
||||||
listenSocketSSL = token;
|
idleTimeout: 60,
|
||||||
console.log('SSL test server is up...');
|
|
||||||
}
|
message: (ws, message, isBinary) => {
|
||||||
|
ws.send(message, isBinary);
|
||||||
|
}
|
||||||
|
}).any('/exit', (res, req) => {
|
||||||
|
/* Shut down everything on this route */
|
||||||
|
if (!closing) {
|
||||||
|
apps.forEach((a) => {
|
||||||
|
uWS.us_listen_socket_close(a.listenSocket);
|
||||||
|
});
|
||||||
|
closing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close this connection */
|
||||||
|
res.close();
|
||||||
|
}).listen(settings.port, (listenSocket) => {
|
||||||
|
if (listenSocket) {
|
||||||
|
/* Add this app with its listenSocket */
|
||||||
|
apps.push({
|
||||||
|
app: app,
|
||||||
|
listenSocket: listenSocket
|
||||||
|
});
|
||||||
|
console.log('Up and running: ' + JSON.stringify(settings));
|
||||||
|
} else {
|
||||||
|
/* Failure here */
|
||||||
|
console.log('Failed to listen, closing everything now');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* non-SSL, non-compression */
|
||||||
|
listenWithSettings({
|
||||||
|
port: 9001,
|
||||||
|
ssl: false,
|
||||||
|
compression: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
/* The non-SSL test server is on port 9001 */
|
/* SSL, shared compressor */
|
||||||
const app = uWS.App().ws('/*', wsBehavior).any('/exit', (res, req) => {
|
listenWithSettings({
|
||||||
/* Stop listening on both SSL and non-SSL */
|
port: 9002,
|
||||||
if (listenSocket) {
|
ssl: true,
|
||||||
uWS.us_listen_socket_close(listenSocket);
|
compression: 1
|
||||||
uWS.us_listen_socket_close(listenSocketSSL);
|
});
|
||||||
listenSocket = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close this connection */
|
/* non-SSL, dedicated compressor */
|
||||||
res.close();
|
listenWithSettings({
|
||||||
}).listen(9001, (token) => {
|
port: 9003,
|
||||||
if (token) {
|
ssl: false,
|
||||||
listenSocket = token;
|
compression: 2
|
||||||
console.log('Non-SSL test server is up...');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* This is required to check for memory leaks */
|
/* This is required to check for memory leaks */
|
||||||
process.on('beforeExit', () => {
|
process.on('exit', () => {
|
||||||
app.forcefully_free();
|
apps.forEach((a) => {
|
||||||
sslApp.forcefully_free();
|
a.app.forcefully_free();
|
||||||
|
});
|
||||||
});
|
});
|
@ -1,14 +1,17 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"outdir": "./reports/servers",
|
"outdir": "./reports/servers",
|
||||||
"servers": [
|
"servers": [
|
||||||
{
|
{
|
||||||
"url": "ws://localhost:9001",
|
"url": "ws://localhost:9001",
|
||||||
"agent": "uWebSockets.js non-SSL, compression 2"
|
"agent": "uWebSockets.js non-SSL, non-compression"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "wss://localhost:9002",
|
"url": "wss://localhost:9002",
|
||||||
"agent": "uWebSockets.js SSL, compression 2"
|
"agent": "uWebSockets.js SSL, shared compressor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "ws://localhost:9003",
|
||||||
|
"agent": "uWebSockets.js non-SSL, dedicated compressor"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"cases": ["*.*"],
|
"cases": ["*.*"],
|
||||||
|
Loading…
Reference in New Issue
Block a user