Test more settings with Autobahn

This commit is contained in:
Alex Hultman 2019-02-10 11:54:44 +01:00
parent d9a6b1010f
commit c4cddb9477
2 changed files with 77 additions and 67 deletions

View File

@ -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,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 60,
/* 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 */
const sslApp = uWS.SSLApp({
key_file_name: 'misc/key.pem', key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem', cert_file_name: 'misc/cert.pem',
passphrase: '1234' passphrase: '1234'
}).ws('/*', wsBehavior).any('/exit', (res, req) => { };
/* Stop listening on both SSL and non-SSL */
if (listenSocket) { /* Create the app */
uWS.us_listen_socket_close(listenSocket); let app = settings.ssl ? uWS.App(sslOptions) : uWS.SSLApp(sslOptions);
uWS.us_listen_socket_close(listenSocketSSL);
listenSocket = null; /* Attach our behavior from settings */
app.ws('/*', {
compression: settings.compression,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 60,
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 */ /* Close this connection */
res.close(); res.close();
}).listen(9002, (token) => { }).listen(settings.port, (listenSocket) => {
if (token) { if (listenSocket) {
listenSocketSSL = token; /* Add this app with its listenSocket */
console.log('SSL test server is up...'); 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();
});
}); });

View File

@ -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": ["*.*"],