Bug 1291199: Retry subprocess perf tests on failure. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 02 Aug 2016 15:37:34 -0700
changeset 395920 462f20138a22d1ce1e66531bf75bb2e2ce6d165e
parent 395919 577158be08e8c1211ffa1198a21e3c059f98f477
child 527090 c4481f62e7a46d679e16443ab0f16a9f8561ec0f
push id24878
push usermaglione.k@gmail.com
push dateWed, 03 Aug 2016 03:34:56 +0000
reviewersaswan
bugs1291199
milestone51.0a1
Bug 1291199: Retry subprocess perf tests on failure. r?aswan MozReview-Commit-ID: 9PDT9tcYFqf
toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js
toolkit/modules/subprocess/test/xpcshell/test_subprocess.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging_perf.js
@@ -5,16 +5,17 @@
 XPCOMUtils.defineLazyModuleGetter(this, "MockRegistry",
                                   "resource://testing-common/MockRegistry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS",
                                   "resource://gre/modules/osfile.jsm");
 
 Cu.import("resource://gre/modules/Subprocess.jsm");
 
 const MAX_ROUND_TRIP_TIME_MS = AppConstants.DEBUG || AppConstants.ASAN ? 36 : 18;
+const MAX_RETRIES = 5;
 
 
 const ECHO_BODY = String.raw`
   import struct
   import sys
 
   while True:
       rawlen = sys.stdin.read(4)
@@ -36,79 +37,83 @@ const SCRIPTS = [
   },
 ];
 
 add_task(function* setup() {
   yield setupHosts(SCRIPTS);
 });
 
 add_task(function* test_round_trip_perf() {
-  let extension = ExtensionTestUtils.loadExtension({
-    background() {
-      let port = browser.runtime.connectNative("echo");
+  let roundTripTime = Infinity;
+  for (let i = 0; i < MAX_RETRIES && roundTripTime > MAX_ROUND_TRIP_TIME_MS; i++) {
+    let extension = ExtensionTestUtils.loadExtension({
+      background() {
+        let port = browser.runtime.connectNative("echo");
 
-      function next() {
-        port.postMessage({
-          "Lorem": {
-            "ipsum": {
-              "dolor": [
-                "sit amet",
-                "consectetur adipiscing elit",
-                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
-              ],
-              "Ut enim": [
-                "ad minim veniam",
-                "quis nostrud exercitation ullamco",
-                "laboris nisi ut aliquip ex ea commodo consequat.",
-              ],
-              "Duis": [
-                "aute irure dolor in reprehenderit in",
-                "voluptate velit esse cillum dolore eu",
-                "fugiat nulla pariatur.",
-              ],
-              "Excepteur": [
-                "sint occaecat cupidatat non proident",
-                "sunt in culpa qui officia deserunt",
-                "mollit anim id est laborum.",
-              ],
+        function next() {
+          port.postMessage({
+            "Lorem": {
+              "ipsum": {
+                "dolor": [
+                  "sit amet",
+                  "consectetur adipiscing elit",
+                  "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
+                ],
+                "Ut enim": [
+                  "ad minim veniam",
+                  "quis nostrud exercitation ullamco",
+                  "laboris nisi ut aliquip ex ea commodo consequat.",
+                ],
+                "Duis": [
+                  "aute irure dolor in reprehenderit in",
+                  "voluptate velit esse cillum dolore eu",
+                  "fugiat nulla pariatur.",
+                ],
+                "Excepteur": [
+                  "sint occaecat cupidatat non proident",
+                  "sunt in culpa qui officia deserunt",
+                  "mollit anim id est laborum.",
+                ],
+              },
             },
-          },
-        });
-      }
-
-      const COUNT = 1000;
-      let now;
-      function finish() {
-        let roundTripTime = (Date.now() - now) / COUNT;
-
-        browser.test.sendMessage("result", roundTripTime);
-      }
-
-      let count = 0;
-      port.onMessage.addListener(msg => {
-        if (count == 0) {
-          // Skip the first round, since it includes the time it takes
-          // the app to start up.
-          now = Date.now();
+          });
         }
 
-        if (count++ <= COUNT) {
-          next();
-        } else {
-          finish();
+        const COUNT = 1000;
+        let now;
+        function finish() {
+          let roundTripTime = (Date.now() - now) / COUNT;
+
+          browser.test.sendMessage("result", roundTripTime);
         }
-      });
+
+        let count = 0;
+        port.onMessage.addListener(msg => {
+          if (count == 0) {
+            // Skip the first round, since it includes the time it takes
+            // the app to start up.
+            now = Date.now();
+          }
 
-      next();
-    },
-    manifest: {
-      permissions: ["nativeMessaging"],
-    },
-  }, ID);
+          if (count++ <= COUNT) {
+            next();
+          } else {
+            finish();
+          }
+        });
 
-  yield extension.startup();
+        next();
+      },
+      manifest: {
+        permissions: ["nativeMessaging"],
+      },
+    }, ID);
 
-  let roundTripTime = yield extension.awaitMessage("result");
+    yield extension.startup();
+
+    roundTripTime = yield extension.awaitMessage("result");
+
+    yield extension.unload();
+  }
+
   ok(roundTripTime <= MAX_ROUND_TRIP_TIME_MS,
      `Expected round trip time (${roundTripTime}ms) to be less than ${MAX_ROUND_TRIP_TIME_MS}ms`);
-
-  yield extension.unload();
 });
--- a/toolkit/modules/subprocess/test/xpcshell/test_subprocess.js
+++ b/toolkit/modules/subprocess/test/xpcshell/test_subprocess.js
@@ -3,16 +3,17 @@
 Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
 
 
 const env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
 
 const MAX_ROUND_TRIP_TIME_MS = AppConstants.DEBUG || AppConstants.ASAN ? 18 : 9;
+const MAX_RETRIES = 5;
 
 let PYTHON;
 let PYTHON_BIN;
 let PYTHON_DIR;
 
 const TEST_SCRIPT = do_get_file("data_test_script.py").path;
 
 let read = pipe => {
@@ -177,48 +178,52 @@ add_task(function* test_subprocess_huge(
 
   let {exitCode} = yield proc.wait();
 
   equal(exitCode, 0, "Got expected exit code");
 });
 
 
 add_task(function* test_subprocess_round_trip_perf() {
-  let proc = yield Subprocess.call({
-    command: PYTHON,
-    arguments: ["-u", TEST_SCRIPT, "echo"],
-  });
+  let roundTripTime = Infinity;
+  for (let i = 0; i < MAX_RETRIES && roundTripTime > MAX_ROUND_TRIP_TIME_MS; i++) {
+    let proc = yield Subprocess.call({
+      command: PYTHON,
+      arguments: ["-u", TEST_SCRIPT, "echo"],
+    });
 
 
-  const LINE = "I'm a leaf on the wind.\n";
+    const LINE = "I'm a leaf on the wind.\n";
+
+    let now = Date.now();
+    const COUNT = 1000;
+    for (let i = 0; i < COUNT; i++) {
+      let [output] = yield Promise.all([
+        read(proc.stdout),
+        proc.stdin.write(LINE),
+      ]);
 
-  let now = Date.now();
-  const COUNT = 1000;
-  for (let i = 0; i < COUNT; i++) {
-    let [output] = yield Promise.all([
-      read(proc.stdout),
-      proc.stdin.write(LINE),
-    ]);
+      // We don't want to log this for every iteration, but we still need
+      // to fail if it goes wrong.
+      if (output !== LINE) {
+        equal(output, LINE, "Got expected output");
+      }
+    }
 
-    // We don't want to log this for every iteration, but we still need
-    // to fail if it goes wrong.
-    if (output !== LINE) {
-      equal(output, LINE, "Got expected output");
-    }
+    roundTripTime = (Date.now() - now) / COUNT;
+
+    yield proc.stdin.close();
+
+    let {exitCode} = yield proc.wait();
+
+    equal(exitCode, 0, "Got expected exit code");
   }
 
-  let roundTripTime = (Date.now() - now) / COUNT;
   ok(roundTripTime <= MAX_ROUND_TRIP_TIME_MS,
      `Expected round trip time (${roundTripTime}ms) to be less than ${MAX_ROUND_TRIP_TIME_MS}ms`);
-
-  yield proc.stdin.close();
-
-  let {exitCode} = yield proc.wait();
-
-  equal(exitCode, 0, "Got expected exit code");
 });
 
 
 add_task(function* test_subprocess_stderr_default() {
   const LINE1 = "I'm a leaf on the wind.\n";
   const LINE2 = "Watch how I soar.\n";
 
   let proc = yield Subprocess.call({