Bug 1459605 - Wait for all workers to have registrationActors before unregistering;r=ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 10 May 2018 03:48:31 +0200
changeset 417727 149fcd977c3d9b87978d1adfe4e7d493edff3426
parent 417726 4092dcafedd0ab03224d824617b5439f67559241
child 417728 4a5d5e1d424099ec68c085946ffa0bb471719f20
push id33978
push userdluca@mozilla.com
push dateThu, 10 May 2018 21:54:47 +0000
treeherdermozilla-central@d302824da0ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko
bugs1459605
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1459605 - Wait for all workers to have registrationActors before unregistering;r=ladybenko MozReview-Commit-ID: 729BNJ1hWxC
devtools/client/application/test/head.js
devtools/client/shared/test/shared-head.js
--- a/devtools/client/application/test/head.js
+++ b/devtools/client/application/test/head.js
@@ -51,19 +51,25 @@ async function openNewTabAndApplicationP
   await target.makeRemote();
 
   let toolbox = await gDevTools.showToolbox(target, "application");
   let panel = toolbox.getCurrentPanel();
   return { panel, tab, target, toolbox };
 }
 
 async function unregisterAllWorkers(client) {
-  info("Unregister all service workers");
+  info("Wait until all workers have a valid registrationActor");
+  let workers;
+  await asyncWaitUntil(async function() {
+    workers = await client.mainRoot.listAllWorkers();
+    const allWorkersRegistered =
+      workers.service.every(worker => !!worker.registrationActor);
+    return allWorkersRegistered;
+  });
 
-  let { service } = await client.mainRoot.listAllWorkers();
-
-  for (let worker of service) {
+  info("Unregister all service workers");
+  for (let worker of workers.service) {
     await client.request({
       to: worker.registrationActor,
       type: "unregister"
     });
   }
 }
--- a/devtools/client/shared/test/shared-head.js
+++ b/devtools/client/shared/test/shared-head.js
@@ -460,16 +460,29 @@ function waitUntil(predicate, interval =
   return new Promise(resolve => {
     setTimeout(function() {
       waitUntil(predicate, interval).then(() => resolve(true));
     }, interval);
   });
 }
 
 /**
+ * Variant of waitUntil that accepts a predicate returning a promise.
+ */
+async function asyncWaitUntil(predicate, interval = 10) {
+  let success = await predicate();
+  while (!success) {
+    // Wait for X milliseconds.
+    await new Promise(resolve => setTimeout(resolve, interval));
+    // Test the predicate again.
+    success = await predicate();
+  }
+}
+
+/**
  * Takes a string `script` and evaluates it directly in the content
  * in potentially a different process.
  */
 let MM_INC_ID = 0;
 function evalInDebuggee(script, browser = gBrowser.selectedBrowser) {
   return new Promise(resolve => {
     let id = MM_INC_ID++;
     let mm = browser.messageManager;