Skip to content

Commit

Permalink
Linting the scripts in the test directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
theturtle32 committed Nov 25, 2014
1 parent a9e7866 commit 17b8809
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 176 deletions.
6 changes: 4 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"unused" : "vars", // vars: Require all defined variables be used, ignore function params
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
Expand Down Expand Up @@ -82,5 +82,7 @@
"yui" : false, // Yahoo User Interface

// Custom Globals
"globals" : {} // additional predefined global variables
"globals" : { // additional predefined global variables
"WebSocket": true
}
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var gulp = require('gulp');
var jshint = require('gulp-jshint');

gulp.task('lint', function() {
return gulp.src(['gulpfile.js', 'lib/**/*.js', 'test/unit/*.js'])
return gulp.src(['gulpfile.js', 'lib/**/*.js', 'test/**/*.js'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish', {verbose: true}))
.pipe(jshint.reporter('fail'));
Expand Down
35 changes: 17 additions & 18 deletions test/scripts/autobahn-test-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/************************************************************************
* Copyright 2010-2011 Worlize Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Expand All @@ -34,14 +34,14 @@ process.argv.forEach(function(value) {
}
});

args.protocol = args.secure ? 'wss:' : 'ws:'
args.protocol = args.secure ? 'wss:' : 'ws:';

console.log("WebSocket-Node: Echo test client for running against the Autobahn test suite");
console.log("Usage: ./libwebsockets-test-client.js --host=127.0.0.1 --port=9000 [--secure]");
console.log("");
console.log('WebSocket-Node: Echo test client for running against the Autobahn test suite');
console.log('Usage: ./libwebsockets-test-client.js --host=127.0.0.1 --port=9000 [--secure]');
console.log('');


console.log("Starting test run.");
console.log('Starting test run.');

getCaseCount(function(caseCount) {
var currentCase = 1;
Expand All @@ -54,9 +54,9 @@ getCaseCount(function(caseCount) {
}
else {
process.nextTick(function() {
console.log("Test suite complete, generating report.");
console.log('Test suite complete, generating report.');
updateReport(function() {
console.log("Report generated.");
console.log('Report generated.');
});
});
}
Expand All @@ -66,7 +66,7 @@ getCaseCount(function(caseCount) {


function runTestCase(caseIndex, caseCount, callback) {
console.log("Running test " + caseIndex + " of " + caseCount);
console.log('Running test ' + caseIndex + ' of ' + caseCount);
var echoClient = new WebSocketClient({
maxReceivedFrameSize: 64*1024*1024, // 64MiB
maxReceivedMessageSize: 64*1024*1024, // 64MiB
Expand All @@ -76,12 +76,12 @@ function runTestCase(caseIndex, caseCount, callback) {
});

echoClient.on('connectFailed', function(error) {
console.log("Connect Error: " + error.toString());
console.log('Connect Error: ' + error.toString());
});

echoClient.on('connect', function(connection) {
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
console.log('Connection Error: ' + error.toString());
});
connection.on('close', function() {
callback();
Expand All @@ -98,10 +98,9 @@ function runTestCase(caseIndex, caseCount, callback) {

var qs = querystring.stringify({
case: caseIndex,
agent: "WebSocket-Node Client v" + wsVersion
agent: 'WebSocket-Node Client v' + wsVersion
});
var url = "ws://" + args.host + ":" + args.port + "/runCase?" + qs;
echoClient.connect("ws://" + args.host + ":" + args.port + "/runCase?" + qs, []);
echoClient.connect('ws://' + args.host + ':' + args.port + '/runCase?' + qs, []);
}

function getCaseCount(callback) {
Expand All @@ -113,11 +112,11 @@ function getCaseCount(callback) {
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Got case count: " + message.utf8Data);
console.log('Got case count: ' + message.utf8Data);
caseCount = parseInt(message.utf8Data, 10);
}
else if (message.type === 'binary') {
throw new Error("Unexpected binary message when retrieving case count");
throw new Error('Unexpected binary message when retrieving case count');
}
});
});
Expand All @@ -127,7 +126,7 @@ function getCaseCount(callback) {
function updateReport(callback) {
var client = new WebSocketClient();
var qs = querystring.stringify({
agent: "WebSocket-Node Client v" + wsVersion
agent: 'WebSocket-Node Client v' + wsVersion
});
client.on('connect', function(connection) {
connection.on('close', callback);
Expand Down
28 changes: 13 additions & 15 deletions test/scripts/echo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
/************************************************************************
* Copyright 2010-2011 Worlize Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***********************************************************************/

var WebSocketServer = require('../../lib/WebSocketServer');
var http = require('http');
var url = require('url');
var fs = require('fs');

var args = { /* defaults */
port: '8080',
Expand All @@ -37,19 +35,19 @@ process.argv.forEach(function(value) {
var port = parseInt(args.port, 10);
var debug = args.debug;

console.log("WebSocket-Node: echo-server");
console.log("Usage: ./echo-server.js [--port=8080] [--debug]");
console.log('WebSocket-Node: echo-server');
console.log('Usage: ./echo-server.js [--port=8080] [--debug]');

var server = http.createServer(function(request, response) {
if (debug) console.log((new Date()) + " Received request for " + request.url);
if (debug) { console.log((new Date()) + ' Received request for ' + request.url); }
response.writeHead(404);
response.end();
});
server.listen(port, function() {
console.log((new Date()) + " Server is listening on port " + port);
console.log((new Date()) + ' Server is listening on port ' + port);
});

wsServer = new WebSocketServer({
var wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: true,
maxReceivedFrameSize: 64*1024*1024, // 64MiB
Expand All @@ -60,11 +58,11 @@ wsServer = new WebSocketServer({
});

wsServer.on('connect', function(connection) {
if (debug) console.log((new Date()) + " Connection accepted" +
" - Protocol Version " + connection.webSocketVersion);
if (debug) { console.log((new Date()) + ' Connection accepted' +
' - Protocol Version ' + connection.webSocketVersion); }
function sendCallback(err) {
if (err) {
console.error("send() error: " + err);
console.error('send() error: ' + err);
connection.drop();
setTimeout(function() {
process.exit(100);
Expand All @@ -73,16 +71,16 @@ wsServer.on('connect', function(connection) {
}
connection.on('message', function(message) {
if (message.type === 'utf8') {
if (debug) console.log("Received utf-8 message of " + message.utf8Data.length + " characters.");
if (debug) { console.log('Received utf-8 message of ' + message.utf8Data.length + ' characters.'); }
connection.sendUTF(message.utf8Data, sendCallback);
}
else if (message.type === 'binary') {
if (debug) console.log("Received Binary Message of " + message.binaryData.length + " bytes");
if (debug) { console.log('Received Binary Message of ' + message.binaryData.length + ' bytes'); }
connection.sendBytes(message.binaryData, sendCallback);
}
});
connection.on('close', function(reasonCode, description) {
if (debug) console.log((new Date()) + " Peer " + connection.remoteAddress + " disconnected.");
if (debug) { console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.'); }
connection._debug.printOutput();
});
});
50 changes: 25 additions & 25 deletions test/scripts/fragmentation-test-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
/************************************************************************
* Copyright 2010-2011 Worlize Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***********************************************************************/

var WebSocketClient = require('../../lib/WebSocketClient');

console.log("WebSocket-Node: Test client for parsing fragmented messages.");
console.log('WebSocket-Node: Test client for parsing fragmented messages.');

var args = { /* defaults */
secure: false,
port: "8080",
host: "127.0.0.1",
"no-defragment": false,
port: '8080',
host: '127.0.0.1',
'no-defragment': false,
binary: false
};

Expand All @@ -36,15 +36,15 @@ process.argv.forEach(function(value) {
}
});

args.protocol = args.secure ? 'wss:' : 'ws:'
args.protocol = args.secure ? 'wss:' : 'ws:';

if (args.help) {
console.log("Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]");
console.log("");
console.log('Usage: ./fragmentation-test-client.js [--host=127.0.0.1] [--port=8080] [--no-defragment] [--binary]');
console.log('');
return;
}
else {
console.log("Use --help for usage information.");
console.log('Use --help for usage information.');
}


Expand All @@ -55,7 +55,7 @@ var client = new WebSocketClient({
});

client.on('connectFailed', function(error) {
console.log("Client Error: " + error.toString())
console.log('Client Error: ' + error.toString());
});


Expand All @@ -65,36 +65,36 @@ var startTime;
var byteCounter;

client.on('connect', function(connection) {
console.log("Connected");
console.log('Connected');
startTime = new Date();
byteCounter = 0;

connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
console.log('Connection Error: ' + error.toString());
});

connection.on('close', function() {
console.log("Connection Closed");
console.log('Connection Closed');
});

connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Received utf-8 message of " + message.utf8Data.length + " characters.");
console.log('Received utf-8 message of ' + message.utf8Data.length + ' characters.');
logThroughput(message.utf8Data.length);
requestData();
}
else {
console.log("Received binary message of " + message.binaryData.length + " bytes.");
console.log('Received binary message of ' + message.binaryData.length + ' bytes.');
logThroughput(message.binaryData.length);
requestData();
}
});

connection.on('frame', function(frame) {
console.log("Frame: 0x" + frame.opcode.toString(16) + "; " + frame.length + " bytes; Flags: " + renderFlags(frame))
console.log('Frame: 0x' + frame.opcode.toString(16) + '; ' + frame.length + ' bytes; Flags: ' + renderFlags(frame));
messageSize += frame.length;
if (frame.fin) {
console.log("Total message size: " + messageSize + " bytes.");
console.log('Total message size: ' + messageSize + ' bytes.');
logThroughput(messageSize);
messageSize = 0;
requestData();
Expand All @@ -106,14 +106,14 @@ client.on('connect', function(connection) {
var duration = (new Date()).valueOf() - startTime.valueOf();
if (duration > 1000) {
var kiloBytesPerSecond = Math.round((byteCounter / 1024) / (duration/1000));
console.log(" Throughput: " + kiloBytesPerSecond + " KBps");
console.log(' Throughput: ' + kiloBytesPerSecond + ' KBps');
startTime = new Date();
byteCounter = 0;
}
};
}

function sendUTFCallback(err) {
if (err) console.error("sendUTF() error: " + err);
if (err) { console.error('sendUTF() error: ' + err); }
}

function requestData() {
Expand Down Expand Up @@ -144,7 +144,7 @@ client.on('connect', function(connection) {
flags.push('[MASK]');
}
if (flags.length === 0) {
return "---";
return '---';
}
return flags.join(' ');
}
Expand All @@ -153,11 +153,11 @@ client.on('connect', function(connection) {
});

if (args['no-defragment']) {
console.log("Not automatically re-assembling fragmented messages.");
console.log('Not automatically re-assembling fragmented messages.');
}
else {
console.log("Maximum aggregate message size: " + client.config.maxReceivedMessageSize + " bytes.");
console.log('Maximum aggregate message size: ' + client.config.maxReceivedMessageSize + ' bytes.');
}
console.log("Connecting");
console.log('Connecting');

client.connect(args.protocol + '//' + args.host + ':' + args.port + '/', 'fragmentation-test');
Loading

0 comments on commit 17b8809

Please sign in to comment.