Bug 1253831 - Don't check actual intervals in the Push backoff test. r=wchen

MozReview-Commit-ID: CUESwtv58LJ

--HG--
extra : rebase_source : 600b8baeeea6334726c88bf1cba64b2d5635c405
This commit is contained in:
Kit Cambridge 2016-03-19 15:29:11 -07:00
Родитель 3836b7c35b
Коммит 8943858ebf
2 изменённых файлов: 13 добавлений и 28 удалений

Просмотреть файл

@ -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() {

Просмотреть файл

@ -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}`);
});
});