Skip to content

Commit

Permalink
[test] Fix Autobahn tests (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
joux3 authored and lpinca committed Nov 15, 2016
1 parent 109db7f commit 4056bde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 61 deletions.
32 changes: 7 additions & 25 deletions test/autobahn-server.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
'use strict';

var WebSocket = require('../');
var WebSocketServer = WebSocket.Server;
const WebSocket = require('../');

process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err, err.stack);
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`);
});

process.on('SIGINT', function () {
try {
console.log('Updating reports and shutting down');
var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
ws.on('close', function () {
process.exit();
});
} catch (e) {
process.exit();
}
});

var wss = new WebSocketServer({port: 8181});
wss.on('connection', function (ws) {
console.log('new connection');
ws.on('message', function (data, flags) {
ws.send(flags.buffer, {binary: flags.binary === true});
});
ws.on('error', function () {
console.log('error', arguments);
});
wss.on('connection', (ws) => {
ws.on('message', (data) => ws.send(data));
ws.on('error', (e) => console.error(e));
});
51 changes: 15 additions & 36 deletions test/autobahn.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
'use strict';

var WebSocket = require('../');
var currentTest = 1;
var lastTest = -1;
var testCount = null;
const WebSocket = require('../');

process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err, err.stack);
});

process.on('SIGINT', function () {
try {
console.log('Updating reports and shutting down');
var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
ws.on('close', function () {
process.exit();
});
} catch (e) {
process.exit();
}
});
let currentTest = 1;
let testCount;

function nextTest () {
var ws;
let ws;

if (currentTest > testCount || (lastTest !== -1 && currentTest > lastTest)) {
console.log('Updating reports and shutting down');
if (currentTest > testCount) {
ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
ws.on('close', function () {
process.exit();
});
return;
}

console.log('Running test case ' + currentTest + '/' + testCount);
ws = new WebSocket('ws://localhost:9001/runCase?case=' + currentTest + '&agent=ws');
ws.on('message', function (data, flags) {
ws.send(flags.buffer, {binary: flags.binary === true, mask: true});
});
ws.on('close', function (data) {
currentTest += 1;
console.log(`Running test case ${currentTest}/${testCount}`);

ws = new WebSocket(`ws://localhost:9001/runCase?case=${currentTest}&agent=ws`);
ws.on('message', (data) => ws.send(data));
ws.on('close', () => {
currentTest++;
process.nextTick(nextTest);
});
ws.on('error', function (e) {});
ws.on('error', (e) => console.error(e));
}

var ws = new WebSocket('ws://localhost:9001/getCaseCount');
ws.on('message', function (data, flags) {
const ws = new WebSocket('ws://localhost:9001/getCaseCount');
ws.on('message', (data) => {
testCount = parseInt(data);
});
ws.on('close', function () {
ws.on('close', () => {
if (testCount > 0) {
nextTest();
}
Expand Down

0 comments on commit 4056bde

Please sign in to comment.