[Pkg-javascript-commits] [node-ws] 02/04: Rewrite the way to fix failing tests

Jérémy Lal kapouer at moszumanska.debian.org
Tue Dec 20 14:09:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

kapouer pushed a commit to branch master
in repository node-ws.

commit e05972dd86c2c1b0e302b584a73ba26796ea785a
Author: Jérémy Lal <kapouer at melix.org>
Date:   Tue Dec 20 15:08:33 2016 +0100

    Rewrite the way to fix failing tests
---
 debian/patches/fix-failing-tests | 844 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 839 insertions(+), 5 deletions(-)

diff --git a/debian/patches/fix-failing-tests b/debian/patches/fix-failing-tests
index 68e5b5a..308122a 100644
--- a/debian/patches/fix-failing-tests
+++ b/debian/patches/fix-failing-tests
@@ -1,16 +1,850 @@
 Description: Fix failing tests
-Author: Ximin Luo <infinity0 at debian.org>
-Forwarded: https://github.com/websockets/ws/pull/671
+ The right move is to let system assign port
+Author: Jérémy Lal <kapouer at melix.org>
+Last-Update: 2016-12-20
+Forwarded: not yet, current upstream too different
 ---
 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
 --- a/test/WebSocketServer.test.js
 +++ b/test/WebSocketServer.test.js
-@@ -5,7 +5,7 @@
+@@ -5,8 +5,6 @@
    , fs = require('fs')
    , should = require('should');
  
 -var port = 8000;
-+var port = 58000;
- 
+-
  function getArrayBuffer(buf) {
    var l = buf.length;
+   var arrayBuf = new ArrayBuffer(l);
+@@ -24,6 +22,10 @@
+   return true;
+ }
+ 
++function getPort(wss) {
++	return wss._server.address().port;
++}
++
+ describe('WebSocketServer', function() {
+   describe('#ctor', function() {
+     it('should return a new instance if called without new', function(done) {
+@@ -31,7 +33,7 @@
+       ws.should.be.an.instanceOf(WebSocketServer);
+       done();
+     });
+-    
++
+     it('throws an error if no option object is passed', function() {
+       var gotException = false;
+       try {
+@@ -66,17 +68,18 @@
+     });
+ 
+     it('emits an error if http server bind fails', function(done) {
+-      var wss1 = new WebSocketServer({port: 50003});
+-      var wss2 = new WebSocketServer({port: 50003});
+-      wss2.on('error', function() {
+-        wss1.close();
+-        done();
++      var wss1 = new WebSocketServer({port: 0}, function() {
++        var wss2 = new WebSocketServer({port: getPort(wss1)});
++        wss2.on('error', function() {
++          wss1.close();
++          done();
++        });
+       });
+     });
+ 
+     it('starts a server on a given port', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        var ws = new WebSocket('ws://localhost:' + port);
++      var wss = new WebSocketServer({port: 0}, function() {
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.close();
+@@ -86,9 +89,9 @@
+ 
+     it('uses a precreated http server', function (done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss = new WebSocketServer({server: srv});
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + srv.address().port);
+ 
+         wss.on('connection', function(client) {
+           wss.close();
+@@ -99,8 +102,8 @@
+     });
+ 
+     it('426s for non-Upgrade requests', function (done) {
+-      var wss = new WebSocketServer({ port: ++port }, function () {
+-        http.get('http://localhost:' + port, function (res) {
++      var wss = new WebSocketServer({ port: 0 }, function () {
++        http.get('http://localhost:' + getPort(wss), function (res) {
+           var body = '';
+ 
+           res.statusCode.should.equal(426);
+@@ -134,9 +137,9 @@
+ 
+     it('emits path specific connection event', function (done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss = new WebSocketServer({server: srv});
+-        var ws = new WebSocket('ws://localhost:' + port+'/endpointName');
++        var ws = new WebSocket('ws://localhost:' + srv.address().port + '/endpointName');
+ 
+         wss.on('connection/endpointName', function(client) {
+           wss.close();
+@@ -148,7 +151,7 @@
+ 
+     it('can have two different instances listening on the same http server with two different paths', function(done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss1 = new WebSocketServer({server: srv, path: '/wss1'})
+           , wss2 = new WebSocketServer({server: srv, path: '/wss2'});
+         var doneCount = 0;
+@@ -166,6 +169,7 @@
+             done();
+           }
+         });
++        var port = srv.address().port;
+         var ws1 = new WebSocket('ws://localhost:' + port + '/wss1');
+         var ws2 = new WebSocket('ws://localhost:' + port + '/wss2?foo=1');
+       });
+@@ -173,7 +177,7 @@
+ 
+     it('cannot have two different instances listening on the same http server with the same path', function(done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss1 = new WebSocketServer({server: srv, path: '/wss1'});
+         try {
+           var wss2 = new WebSocketServer({server: srv, path: '/wss1'});
+@@ -186,25 +190,24 @@
+       });
+     });
+     it('will not crash when it receives an unhandled opcode', function(done) {
+-      var wss = new WebSocketServer({ port: 8080 });
++      var wss = new WebSocketServer({ port: 0 }, function() {
++        var socket = new WebSocket('ws://127.0.0.1:' + getPort(wss) + '/');
++        socket.onopen = function() {
++            socket._socket.write(new Buffer([5]));
++            socket.send('');
++        };
++      });
+       wss.on('connection', function connection(ws) {
+           ws.onerror = function(error) {
+               done();
+           };
+       });
+-
+-      var socket = new WebSocket('ws://127.0.0.1:8080/');
+-
+-      socket.onopen = function() {
+-          socket._socket.write(new Buffer([5]));
+-          socket.send('');
+-      };
+-    });  
++    });
+   });
+ 
+   describe('#close', function() {
+     it('does not thrown when called twice', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
++      var wss = new WebSocketServer({port: 0}, function() {
+         wss.close();
+         wss.close();
+         wss.close();
+@@ -214,8 +217,8 @@
+     });
+ 
+     it('will close all clients', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        var ws = new WebSocket('ws://localhost:' + port);
++      var wss = new WebSocketServer({port: 0}, function() {
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+         ws.on('close', function() {
+           if (++closes == 2) done();
+         });
+@@ -235,9 +238,9 @@
+       srv.close = function() {
+         should.fail('must not close pre-created server');
+       }
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss = new WebSocketServer({server: srv});
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+         wss.on('connection', function(client) {
+           wss.close();
+           srv.close = realClose;
+@@ -249,7 +252,7 @@
+ 
+     it('cleans event handlers on precreated server', function(done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function() {
++      srv.listen(0, function() {
+         var wss = new WebSocketServer({server: srv});
+         wss.close();
+         srv.emit('upgrade');
+@@ -261,7 +264,7 @@
+ 
+     it('cleans up websocket data on a precreated server', function(done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss1 = new WebSocketServer({server: srv, path: '/wss1'})
+           , wss2 = new WebSocketServer({server: srv, path: '/wss2'});
+         (typeof srv._webSocketPaths).should.eql('object');
+@@ -278,9 +281,9 @@
+ 
+   describe('#clients', function() {
+     it('returns a list of connected clients', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
++      var wss = new WebSocketServer({port: 0}, function() {
+         wss.clients.length.should.eql(0);
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.clients.length.should.eql(1);
+@@ -290,9 +293,9 @@
+     });
+ 
+     it('can be disabled', function(done) {
+-      var wss = new WebSocketServer({port: ++port, clientTracking: false}, function() {
++      var wss = new WebSocketServer({port: 0, clientTracking: false}, function() {
+         wss.clients.length.should.eql(0);
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.clients.length.should.eql(0);
+@@ -303,8 +306,8 @@
+ 
+     it('is updated when client terminates the connection', function(done) {
+       var ws;
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        ws = new WebSocket('ws://localhost:' + port);
++      var wss = new WebSocketServer({port: 0}, function() {
++        ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         client.on('close', function() {
+@@ -318,8 +321,8 @@
+ 
+     it('is updated when client closes the connection', function(done) {
+       var ws;
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        ws = new WebSocket('ws://localhost:' + port);
++      var wss = new WebSocketServer({port: 0}, function() {
++        ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         client.on('close', function() {
+@@ -334,8 +337,8 @@
+ 
+   describe('#options', function() {
+     it('exposes options passed to constructor', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        wss.options.port.should.eql(port);
++      var wss = new WebSocketServer({port: 0}, function() {
++        wss.options.port.should.eql(0);
+         wss.close();
+         done();
+       });
+@@ -345,9 +348,9 @@
+   describe('#maxpayload #hybiOnly', function() {
+     it('maxpayload is passed on to clients,', function(done) {
+       var _maxPayload = 20480;
+-      var wss = new WebSocketServer({port: ++port,maxPayload:_maxPayload, disableHixie: true}, function() {
++      var wss = new WebSocketServer({port: 0,maxPayload:_maxPayload, disableHixie: true}, function() {
+         wss.clients.length.should.eql(0);
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.clients.length.should.eql(1);
+@@ -358,9 +361,9 @@
+     });
+     it('maxpayload is passed on to hybi receivers', function(done) {
+       var _maxPayload = 20480;
+-      var wss = new WebSocketServer({port: ++port,maxPayload:_maxPayload,  disableHixie: true}, function() {
++      var wss = new WebSocketServer({port: 0,maxPayload:_maxPayload,  disableHixie: true}, function() {
+         wss.clients.length.should.eql(0);
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.clients.length.should.eql(1);
+@@ -372,9 +375,9 @@
+     it('maxpayload is passed on to permessage-deflate', function(done) {
+       var PerMessageDeflate = require('../lib/PerMessageDeflate');
+       var _maxPayload = 20480;
+-      var wss = new WebSocketServer({port: ++port,maxPayload:_maxPayload, disableHixie: true}, function() {
++      var wss = new WebSocketServer({port: 0,maxPayload:_maxPayload, disableHixie: true}, function() {
+         wss.clients.length.should.eql(0);
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + getPort(wss));
+       });
+       wss.on('connection', function(client) {
+         wss.clients.length.should.eql(1);
+@@ -388,14 +391,14 @@
+   describe('#handleUpgrade', function() {
+     it('can be used for a pre-existing server', function (done) {
+       var srv = http.createServer();
+-      srv.listen(++port, function () {
++      srv.listen(0, function () {
+         var wss = new WebSocketServer({noServer: true});
+         srv.on('upgrade', function(req, socket, upgradeHead) {
+           wss.handleUpgrade(req, socket, upgradeHead, function(client) {
+             client.send('hello');
+           });
+         });
+-        var ws = new WebSocket('ws://localhost:' + port);
++        var ws = new WebSocket('ws://localhost:' + srv.address().port);
+         ws.on('message', function(message) {
+           message.should.eql('hello');
+           wss.close();
+@@ -409,9 +412,9 @@
+   describe('hybi mode', function() {
+     describe('connection establishing', function() {
+       it('does not accept connections with no sec-websocket-key', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -433,9 +436,9 @@
+       });
+ 
+       it('does not accept connections with no sec-websocket-version', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -458,9 +461,9 @@
+       });
+ 
+       it('does not accept connections with invalid sec-websocket-version', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -484,11 +487,11 @@
+       });
+ 
+       it('client can be denied', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -515,11 +518,11 @@
+       });
+ 
+       it('client can be accepted', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return true;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -542,13 +545,13 @@
+ 
+       it('verifyClient gets client origin', function(done) {
+         var verifyClientCalled = false;
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(info) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(info) {
+           info.origin.should.eql('http://foobarbaz.com');
+           verifyClientCalled = true;
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -571,13 +574,13 @@
+ 
+       it('verifyClient gets original request', function(done) {
+         var verifyClientCalled = false;
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(info) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(info) {
+           info.req.headers['sec-websocket-key'].should.eql('dGhlIHNhbXBsZSBub25jZQ==');
+           verifyClientCalled = true;
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -615,8 +618,8 @@
+             return true;
+           }
+         });
+-        app.listen(++port, function() {
+-          var ws = new WebSocket('wss://localhost:' + port);
++        app.listen(0, function() {
++          var ws = new WebSocket('wss://localhost:' + app.address().port);
+         });
+         wss.on('connection', function(ws) {
+           app.close();
+@@ -640,8 +643,8 @@
+             return true;
+           }
+         });
+-        app.listen(++port, function() {
+-          var ws = new WebSocket('ws://localhost:' + port);
++        app.listen(0, function() {
++          var ws = new WebSocket('ws://localhost:' + app.address().port);
+         });
+         wss.on('connection', function(ws) {
+           app.close();
+@@ -653,13 +656,13 @@
+       });
+ 
+       it('client can be denied asynchronously', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           process.nextTick(function() {
+             cb(false);
+           });
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -686,13 +689,13 @@
+       });
+ 
+       it('client can be denied asynchronously with custom response code', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           process.nextTick(function() {
+             cb(false, 404);
+           });
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -719,13 +722,13 @@
+       });
+ 
+       it('client can be accepted asynchronously', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           process.nextTick(function() {
+             cb(true);
+           });
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -747,11 +750,11 @@
+       });
+ 
+       it('handles messages passed along with the upgrade request (upgrade head)', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return true;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -777,8 +780,8 @@
+       });
+ 
+       it('selects the first protocol by default', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port, ['prot1', 'prot2']);
++        var wss = new WebSocketServer({port: 0}, function() {
++          var ws = new WebSocket('ws://localhost:' + getPort(wss), ['prot1', 'prot2']);
+           ws.on('open', function(client) {
+               ws.protocol.should.eql('prot1');
+               wss.close();
+@@ -788,9 +791,9 @@
+       });
+ 
+       it('selects the last protocol via protocol handler', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+             cb(true, ps[ps.length-1]); }}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port, ['prot1', 'prot2']);
++          var ws = new WebSocket('ws://localhost:' + getPort(wss), ['prot1', 'prot2']);
+           ws.on('open', function(client) {
+               ws.protocol.should.eql('prot2');
+               wss.close();
+@@ -800,9 +803,9 @@
+       });
+ 
+       it('client detects invalid server protocol', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+             cb(true, 'prot3'); }}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port, ['prot1', 'prot2']);
++          var ws = new WebSocket('ws://localhost:' + getPort(wss), ['prot1', 'prot2']);
+           ws.on('open', function(client) {
+               done(new Error('connection must not be established'));
+           });
+@@ -813,9 +816,9 @@
+       });
+ 
+       it('client detects no server protocol', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+             cb(true); }}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port, ['prot1', 'prot2']);
++          var ws = new WebSocket('ws://localhost:' + getPort(wss), ['prot1', 'prot2']);
+           ws.on('open', function(client) {
+               done(new Error('connection must not be established'));
+           });
+@@ -826,9 +829,9 @@
+       });
+ 
+       it('client refuses server protocols', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+             cb(false); }}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port, ['prot1', 'prot2']);
++          var ws = new WebSocket('ws://localhost:' + getPort(wss), ['prot1', 'prot2']);
+           ws.on('open', function(client) {
+               done(new Error('connection must not be established'));
+           });
+@@ -839,11 +842,11 @@
+       });
+ 
+       it('server detects unauthorized protocol handler', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+           cb(false);
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -853,7 +856,6 @@
+               'Sec-WebSocket-Origin': 'http://foobar.com'
+             }
+           };
+-          options.port = port;
+           var req = http.request(options);
+           req.end();
+           req.on('response', function(res) {
+@@ -869,11 +871,11 @@
+       });
+ 
+       it('server detects invalid protocol handler', function(done) {
+-        var wss = new WebSocketServer({port: ++port, handleProtocols: function(ps, cb) {
++        var wss = new WebSocketServer({port: 0, handleProtocols: function(ps, cb) {
+             // not calling callback is an error and shouldn't timeout
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -883,7 +885,6 @@
+               'Sec-WebSocket-Origin': 'http://foobar.com'
+             }
+           };
+-          options.port = port;
+           var req = http.request(options);
+           req.end();
+           req.on('response', function(res) {
+@@ -899,9 +900,9 @@
+       });
+ 
+       it('accept connections with sec-websocket-extensions', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -930,8 +931,8 @@
+           data[i] = String.fromCharCode(65 + ~~(25 * Math.random()));
+         }
+         data = data.join('');
+-        var wss = new WebSocketServer({port: ++port}, function() {
+-          var ws = new WebSocket('ws://localhost:' + port);
++        var wss = new WebSocketServer({port: 0}, function() {
++          var ws = new WebSocket('ws://localhost:' + getPort(wss));
+           ws.on('message', function(message, flags) {
+             ws.send(message);
+           });
+@@ -950,9 +951,9 @@
+ 
+   describe('hixie mode', function() {
+     it('can be disabled', function(done) {
+-      var wss = new WebSocketServer({port: ++port, disableHixie: true}, function() {
++      var wss = new WebSocketServer({port: 0, disableHixie: true}, function() {
+         var options = {
+-          port: port,
++          port: getPort(wss),
+           host: '127.0.0.1',
+           headers: {
+             'Connection': 'Upgrade',
+@@ -980,9 +981,9 @@
+ 
+     describe('connection establishing', function() {
+       it('does not accept connections with no sec-websocket-key1', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1005,9 +1006,9 @@
+       });
+ 
+       it('does not accept connections with no sec-websocket-key2', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1030,9 +1031,9 @@
+       });
+ 
+       it('accepts connections with valid handshake', function(done) {
+-        var wss = new WebSocketServer({port: ++port}, function() {
++        var wss = new WebSocketServer({port: 0}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1054,11 +1055,11 @@
+       });
+ 
+       it('client can be denied', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1085,11 +1086,11 @@
+       });
+ 
+       it('client can be accepted', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return true;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1112,13 +1113,13 @@
+ 
+       it('verifyClient gets client origin', function(done) {
+         var verifyClientCalled = false;
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(info) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(info) {
+           info.origin.should.eql('http://foobarbaz.com');
+           verifyClientCalled = true;
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1142,13 +1143,13 @@
+ 
+       it('verifyClient gets original request', function(done) {
+         var verifyClientCalled = false;
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(info) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(info) {
+           info.req.headers['sec-websocket-key1'].should.eql('3e6b263  4 17 80');
+           verifyClientCalled = true;
+           return false;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1171,11 +1172,11 @@
+       });
+ 
+       it('client can be denied asynchronously', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           cb(false);
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1203,11 +1204,11 @@
+       });
+ 
+       it('client can be denied asynchronously with custom response code', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           cb(false, 404, 'Not Found');
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1235,11 +1236,11 @@
+       });
+ 
+       it('client can be accepted asynchronously', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o, cb) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o, cb) {
+           cb(true);
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1261,11 +1262,11 @@
+       });
+ 
+       it('handles messages passed along with the upgrade request (upgrade head)', function(done) {
+-        var wss = new WebSocketServer({port: ++port, verifyClient: function(o) {
++        var wss = new WebSocketServer({port: 0, verifyClient: function(o) {
+           return true;
+         }}, function() {
+           var options = {
+-            port: port,
++            port: getPort(wss),
+             host: '127.0.0.1',
+             headers: {
+               'Connection': 'Upgrade',
+@@ -1295,8 +1296,8 @@
+ 
+   describe('client properties', function() {
+     it('protocol is exposed', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        var ws = new WebSocket('ws://localhost:' + port, 'hi');
++      var wss = new WebSocketServer({port: 0}, function() {
++        var ws = new WebSocket('ws://localhost:' + getPort(wss), 'hi');
+       });
+       wss.on('connection', function(client) {
+         client.protocol.should.eql('hi');
+@@ -1306,8 +1307,8 @@
+     });
+ 
+     it('protocolVersion is exposed', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        var ws = new WebSocket('ws://localhost:' + port, {protocolVersion: 8});
++      var wss = new WebSocketServer({port: 0}, function() {
++        var ws = new WebSocket('ws://localhost:' + getPort(wss), {protocolVersion: 8});
+       });
+       wss.on('connection', function(client) {
+         client.protocolVersion.should.eql(8);
+@@ -1317,8 +1318,8 @@
+     });
+ 
+     it('upgradeReq is the original request object', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
+-        var ws = new WebSocket('ws://localhost:' + port, {protocolVersion: 8});
++      var wss = new WebSocketServer({port: 0}, function() {
++        var ws = new WebSocket('ws://localhost:' + getPort(wss), {protocolVersion: 8});
+       });
+       wss.on('connection', function(client) {
+         client.upgradeReq.httpVersion.should.eql('1.1');
+@@ -1330,9 +1331,9 @@
+ 
+   describe('permessage-deflate', function() {
+     it('accept connections with permessage-deflate extension', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
++      var wss = new WebSocketServer({port: 0}, function() {
+         var options = {
+-          port: port,
++          port: getPort(wss),
+           host: '127.0.0.1',
+           headers: {
+             'Connection': 'Upgrade',
+@@ -1354,9 +1355,9 @@
+     });
+ 
+     it('does not accept connections with not defined extension parameter', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
++      var wss = new WebSocketServer({port: 0}, function() {
+         var options = {
+-          port: port,
++          port: getPort(wss),
+           host: '127.0.0.1',
+           headers: {
+             'Connection': 'Upgrade',
+@@ -1381,9 +1382,9 @@
+     });
+ 
+     it('does not accept connections with invalid extension parameter', function(done) {
+-      var wss = new WebSocketServer({port: ++port}, function() {
++      var wss = new WebSocketServer({port: 0}, function() {
+         var options = {
+-          port: port,
++          port: getPort(wss),
+           host: '127.0.0.1',
+           headers: {
+             'Connection': 'Upgrade',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ws.git



More information about the Pkg-javascript-commits mailing list