Skip to content
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

Merged
merged 6 commits into from
Nov 15, 2016
Merged

Fix Autobahn tests #894

merged 6 commits into from
Nov 15, 2016

Conversation

joux3
Copy link
Contributor

@joux3 joux3 commented Nov 15, 2016

The test files used an older API for message events.

@lpinca
Copy link
Member

lpinca commented Nov 15, 2016

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!

@3rd-Eden
Copy link
Member

@lpinca Yeah, thats why I didn't want to merge this yet. I knew you had it working against the current code base.

@joux3
Copy link
Contributor Author

joux3 commented Nov 15, 2016

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});
Copy link
Member

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?

Copy link
Contributor Author

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');
Copy link
Member

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);
Copy link
Member

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');
Copy link
Member

@lpinca lpinca Nov 15, 2016

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`));
Copy link
Member

@lpinca lpinca Nov 15, 2016

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(...);
});

@lpinca lpinca merged commit 4056bde into websockets:master Nov 15, 2016
@lpinca
Copy link
Member

lpinca commented Nov 15, 2016

Thanks a lot.

@joux3 joux3 deleted the fix-autobahn-tests branch November 21, 2016 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants