-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Autobahn tests #894
Fix Autobahn tests #894
Conversation
Both files can be simplified a lot. This is what I used recently: Server 'use strict';
const WebSocket = require('..');
const wss = new WebSocket.Server({
perMessageDeflate: { threshold: 0 },
port: 9001
}, () => console.log('server listening on *:9001'));
wss.on('connection', (ws) => {
ws.on('error', (err) => console.error(err.stack));
ws.on('message', (msg) => ws.send(msg));
}); Client 'use strict';
const WebSocket = require('..');
let currentTest = 1;
let testCount;
function nextTest () {
let ws;
if (currentTest > testCount) {
ws = new WebSocket('ws://localhost:9001/updateReports?&agent=ws');
return;
}
console.log(`Running test case ${currentTest}/${testCount}`);
ws = new WebSocket(`ws://localhost:9001/runCase?case=${currentTest}&agent=ws`);
ws.on('error', (err) => console.error(err.stack));
ws.on('message', (data) => ws.send(data));
ws.on('close', () => {
currentTest++;
process.nextTick(nextTest);
});
}
const ws = new WebSocket('ws://localhost:9001/getCaseCount');
ws.on('message', (data) => {
testCount = +data;
});
ws.on('close', () => {
if (testCount > 0) nextTest();
}); Since I totally forgot to do it, would you mind updating this PR to also modernize/clean up the code? Thanks! |
@lpinca Yeah, thats why I didn't want to merge this yet. I knew you had it working against the current code base. |
Done. Though my files look awfully like the ones you just posted. |
|
||
var wss = new WebSocketServer({port: 8181}); | ||
wss.on('connection', function (ws) { | ||
const wss = new WebSocket.Server({port: 8181}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default Autobahn runs on port 9001, can you please use this port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand the Autobahn report generator also runs on 9001
. Maybe I'll add a runtime option for that while defaulting to 9001
.
var wss = new WebSocketServer({port: 8181}); | ||
wss.on('connection', function (ws) { | ||
const wss = new WebSocket.Server({port: 8181}); | ||
wss.on('connection', (ws) => { | ||
console.log('new connection'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop this line, it's just useless noise.
ws.on('error', function () { | ||
console.log('error', arguments); | ||
ws.on('message', (data) => { | ||
ws.send(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you merge this line with the one above?
process.nextTick(nextTest); | ||
}); | ||
ws.on('error', function (e) {}); | ||
ws.on('error', (e) => console.error(e)); | ||
} | ||
|
||
var ws = new WebSocket('ws://localhost:9001/getCaseCount'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore: const
instead of var
.
}); | ||
const port = process.argv.length > 2 ? parseInt(process.argv[2]) : 9001; | ||
const wss = new WebSocket.Server({ port }, | ||
() => console.log(`Listening to port ${port}. Use extra argument to define the port`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style nit, feel free to ignore:
const wss = new WebSocket.Server({ port }, () => {
console.log(...);
});
Thanks a lot. |
The test files used an older API for
message
events.