Fix tests
This commit is contained in:
parent
3ea254d0db
commit
cc6a44f35d
4 changed files with 29 additions and 25 deletions
|
@ -38430,11 +38430,13 @@ TextSecureWebSocket = function (url) {
|
|||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var calledClose = false;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
getStatus : function() { return socket.readyState; },
|
||||
close : function() { calledClose = true; }
|
||||
};
|
||||
var error;
|
||||
|
||||
|
@ -38455,7 +38457,7 @@ TextSecureWebSocket = function (url) {
|
|||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
if (!error && !calledClose) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
|
|
|
@ -38429,11 +38429,13 @@ TextSecureWebSocket = function (url) {
|
|||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var calledClose = false;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
getStatus : function() { return socket.readyState; },
|
||||
close : function() { calledClose = true; }
|
||||
};
|
||||
var error;
|
||||
|
||||
|
@ -38454,7 +38456,7 @@ TextSecureWebSocket = function (url) {
|
|||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
if (!error && !calledClose) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
|
|
|
@ -15,47 +15,45 @@
|
|||
*/
|
||||
|
||||
describe('TextSecureWebSocket', function() {
|
||||
var WebSocket = window.WebSocket;
|
||||
var RealWebSocket = window.WebSocket;
|
||||
before(function() { window.WebSocket = MockSocket; });
|
||||
after (function() { window.WebSocket = WebSocket; });
|
||||
it('connects a websocket', function(done) {
|
||||
after (function() { window.WebSocket = RealWebSocket; });
|
||||
it('connects and disconnects', function(done) {
|
||||
var mockServer = new MockServer('ws://localhost:8080');
|
||||
mockServer.on('connection', function(server) {
|
||||
server.on('message', function(data) {
|
||||
server.send('hello');
|
||||
});
|
||||
});
|
||||
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||
socket.onmessage = function(response) {
|
||||
assert.strictEqual(response.data, 'hello');
|
||||
socket.close();
|
||||
server.close();
|
||||
done();
|
||||
};
|
||||
socket.send('data');
|
||||
});
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||
});
|
||||
|
||||
it('sends a keepalive once a minute', function(done) {
|
||||
this.timeout(60000);
|
||||
var mockServer = new MockServer('ws://localhost:8080');
|
||||
var mockServer = new MockServer('ws://localhost:8081');
|
||||
mockServer.on('connection', function(server) {
|
||||
server.on('message', function(data) {
|
||||
var message = textsecure.protobuf.WebSocketMessage.decode(data);
|
||||
assert.strictEqual(message.type, textsecure.protobuf.WebSocketMessage.Type.REQUEST);
|
||||
assert.strictEqual(message.request.verb, 'GET');
|
||||
assert.strictEqual(message.request.path, '/v1/keepalive');
|
||||
socket.close();
|
||||
server.close();
|
||||
done();
|
||||
});
|
||||
});
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8081');
|
||||
});
|
||||
|
||||
it('reconnects', function(done) {
|
||||
this.timeout(60000);
|
||||
var mockServer = new MockServer('ws://localhost:8080');
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8080');
|
||||
var mockServer = new MockServer('ws://localhost:8082');
|
||||
var socket = new TextSecureWebSocket('ws://localhost:8082');
|
||||
socket.onclose = function() {
|
||||
var mockServer = new MockServer('ws://localhost:8080');
|
||||
mockServer.on('connection', function() {
|
||||
var mockServer = new MockServer('ws://localhost:8082');
|
||||
mockServer.on('connection', function(server) {
|
||||
socket.close();
|
||||
server.close();
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -28,11 +28,13 @@ TextSecureWebSocket = function (url) {
|
|||
var reconnectSemaphore = 0;
|
||||
var reconnectTimeout = 1000;
|
||||
var socket;
|
||||
var calledClose = false;
|
||||
var socketWrapper = {
|
||||
onmessage : function() {},
|
||||
onclose : function() {},
|
||||
onerror : function() {},
|
||||
getStatus : function() { return socket.readyState; }
|
||||
getStatus : function() { return socket.readyState; },
|
||||
close : function() { calledClose = true; }
|
||||
};
|
||||
var error;
|
||||
|
||||
|
@ -53,7 +55,7 @@ TextSecureWebSocket = function (url) {
|
|||
};
|
||||
|
||||
function onclose(e) {
|
||||
if (!error) {
|
||||
if (!error && !calledClose) {
|
||||
reconnectSemaphore--;
|
||||
setTimeout(connect, reconnectTimeout);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue