diff --git a/dom/push/PushServiceWebSocket.jsm b/dom/push/PushServiceWebSocket.jsm index 45f67a6c0557..f2dbdb557428 100644 --- a/dom/push/PushServiceWebSocket.jsm +++ b/dom/push/PushServiceWebSocket.jsm @@ -170,11 +170,6 @@ this.PushServiceWebSocket = { if (timer == this._backoffTimer) { console.debug("onTimerFired: Reconnecting after backoff"); - if (this._reconnectTestCallback) { - // Notify the test callback once the client reconnects. - let actualRetryTimeout = Date.now() - this._lastDisconnect; - this._reconnectTestCallback(actualRetryTimeout); - } this._beginWSSetup(); return; } @@ -331,9 +326,6 @@ this.PushServiceWebSocket = { */ _lastPingTime: 0, - /** The last time the connection was closed. */ - _lastDisconnect: 0, - /** * A one-shot timer used to ping the server, to avoid timing out idle * connections. Reset to the ping interval on each incoming message. @@ -343,15 +335,6 @@ this.PushServiceWebSocket = { /** A one-shot timer fired after the reconnect backoff period. */ _backoffTimer: null, - /** - * A function called when the client reconnects after backing off. - * - * @param {Number} actualRetryTimeout The time elapsed between the last - * disconnect and reconnect time. This should be >= the backoff delay for - * that attempt. - */ - _reconnectTestCallback: null, - /** * Sends a message to the Push Server through an open websocket. * typeof(msg) shall be an object @@ -434,8 +417,6 @@ this.PushServiceWebSocket = { this._notifyRequestQueue(); this._notifyRequestQueue = null; } - - this._lastDisconnect = Date.now(); }, uninit: function() { diff --git a/dom/push/test/xpcshell/test_retry_ws.js b/dom/push/test/xpcshell/test_retry_ws.js index 32471a408331..e81e54c7dd82 100644 --- a/dom/push/test/xpcshell/test_retry_ws.js +++ b/dom/push/test/xpcshell/test_retry_ws.js @@ -11,7 +11,7 @@ function run_test() { do_get_profile(); setPrefs({ userAgentID: userAgentID, - pingInterval: 10000, + pingInterval: 2000, retryBaseInterval: 25, }); run_next_test(); @@ -30,9 +30,17 @@ add_task(function* test_ws_retry() { quota: Infinity, }); - let alarmDelays = []; - PushServiceWebSocket._reconnectTestCallback = function(delay) { - alarmDelays.push(delay); + // Use a mock timer to avoid waiting for the backoff interval. + let reconnects = 0; + PushServiceWebSocket._backoffTimer = { + init(observer, delay, type) { + reconnects++; + ok(delay >= 5 && delay <= 2000, `Backoff delay ${ + delay} out of range for attempt ${reconnects}`); + observer.observe(this, "timer-callback", null); + }, + + cancel() {}, }; let handshakeDone; @@ -43,7 +51,7 @@ add_task(function* test_ws_retry() { makeWebSocket(uri) { return new MockWebSocket(uri, { onHello(request) { - if (alarmDelays.length == 10) { + if (reconnects == 10) { this.serverSendMsg(JSON.stringify({ messageType: 'hello', status: 200, @@ -59,8 +67,4 @@ add_task(function* test_ws_retry() { }); yield handshakePromise; - [25, 50, 100, 200, 400, 800, 1600, 3200, 6400, 10000].forEach(function(minDelay, index) { - ok(alarmDelays[index] >= minDelay, `Should wait at least ${ - minDelay}ms before attempt ${index + 1}`); - }); });