Bug 1253831 - Don't check actual intervals in the Push backoff test. r=wchen, a=test-only
authorKit Cambridge <kcambridge@mozilla.com>
Sat, 19 Mar 2016 15:29:11 -0700
changeset 323762 7c164deed2231846aceaf869fa251d1ce8052d01
parent 323761 477b227b6224431e51ac256e37e96498e4843cf4
child 323763 85ba0f8d7f904b8c29bfaf3b4fe81778ca8bdc28
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen, test-only
bugs1253831
milestone47.0a2
Bug 1253831 - Don't check actual intervals in the Push backoff test. r=wchen, a=test-only MozReview-Commit-ID: CUESwtv58LJ
dom/push/PushServiceWebSocket.jsm
dom/push/test/xpcshell/test_retry_ws.js
--- a/dom/push/PushServiceWebSocket.jsm
+++ b/dom/push/PushServiceWebSocket.jsm
@@ -165,21 +165,16 @@ this.PushServiceWebSocket = {
 
     if (timer == this._pingTimer) {
       this._sendPing();
       return;
     }
 
     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;
     }
 
     if (timer == this._requestTimeoutTimer) {
       this._timeOutRequests();
       return;
     }
@@ -326,38 +321,26 @@ this.PushServiceWebSocket = {
 
   /**
    * The last time the client sent a ping to the server. If non-zero, keeps the
    * request timeout timer active. Reset to zero when the server responds with
    * a pong or pending messages.
    */
   _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.
    */
   _pingTimer: null,
 
   /** 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
    */
   _wsSendMessage: function(msg) {
     if (!this._ws) {
       console.warn("wsSendMessage: No WebSocket initialized.",
         "Cannot send a message");
       return;
@@ -429,18 +412,16 @@ this.PushServiceWebSocket = {
     if (shouldCancelPending) {
       this._cancelRegisterRequests();
     }
 
     if (this._notifyRequestQueue) {
       this._notifyRequestQueue();
       this._notifyRequestQueue = null;
     }
-
-    this._lastDisconnect = Date.now();
   },
 
   uninit: function() {
     if (this._udpServer) {
       this._udpServer.close();
       this._udpServer = null;
     }
 
--- a/dom/push/test/xpcshell/test_retry_ws.js
+++ b/dom/push/test/xpcshell/test_retry_ws.js
@@ -6,17 +6,17 @@
 const {PushDB, PushService, PushServiceWebSocket} = serviceExports;
 
 const userAgentID = '05f7b940-51b6-4b6f-8032-b83ebb577ded';
 
 function run_test() {
   do_get_profile();
   setPrefs({
     userAgentID: userAgentID,
-    pingInterval: 10000,
+    pingInterval: 2000,
     retryBaseInterval: 25,
   });
   run_next_test();
 }
 
 add_task(function* test_ws_retry() {
   let db = PushServiceWebSocket.newPushDB();
   do_register_cleanup(() => {return db.drop().then(_ => db.close());});
@@ -25,42 +25,46 @@ add_task(function* test_ws_retry() {
     channelID: '61770ba9-2d57-4134-b949-d40404630d5b',
     pushEndpoint: 'https://example.org/push/1',
     scope: 'https://example.net/push/1',
     version: 1,
     originAttributes: '',
     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;
   let handshakePromise = new Promise(resolve => handshakeDone = resolve);
   PushService.init({
     serverURI: "wss://push.example.org/",
     networkInfo: new MockDesktopNetworkInfo(),
     makeWebSocket(uri) {
       return new MockWebSocket(uri, {
         onHello(request) {
-          if (alarmDelays.length == 10) {
+          if (reconnects == 10) {
             this.serverSendMsg(JSON.stringify({
               messageType: 'hello',
               status: 200,
               uaid: userAgentID,
             }));
             handshakeDone();
             return;
           }
           this.serverInterrupt();
         },
       });
     },
   });
 
   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}`);
-  });
 });