Bug 1515390 - Make memory reporter tests work with the socket process. r=erahm
authorDragana Damjanovic <dd.mozilla@gmail.com>
Wed, 16 Jan 2019 22:24:57 +0000
changeset 514159 5b6434fa88d4595c3990604ef99c95d1c8ca48e7
parent 514158 8d4aa37d713744c3b6713c0c5fa3cecef535ee74
child 514160 fad773445014ef73076aae5f2460984c79b37a3c
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1515390
milestone66.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 1515390 - Make memory reporter tests work with the socket process. r=erahm Differential Revision: https://phabricator.services.mozilla.com/D15022
toolkit/components/aboutmemory/tests/test_aboutmemory5.xul
toolkit/components/aboutmemory/tests/test_memoryReporters.xul
toolkit/components/aboutmemory/tests/test_memoryReporters2.xul
xpcom/base/nsMemoryReporterManager.cpp
--- a/toolkit/components/aboutmemory/tests/test_aboutmemory5.xul
+++ b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xul
@@ -19,16 +19,20 @@
 
   <script type="application/javascript">
   <![CDATA[
   "use strict";
 
   let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
             getService(Ci.nsIMemoryReporterManager);
 
+  let socketProcessRunning = 0;
+  if (SpecialPowers.getBoolPref("network.process.enabled")) {
+    socketProcessRunning = 1;
+  }
   let numRemotes = 3;
   let numReady = 0;
 
   // Create some remote processes, and set up message-passing so that
   // we know when each child is fully initialized.
   let remotes = [];
 
   let prefs = [
@@ -123,17 +127,18 @@
           }
 
           // Note: Match "vsize" but not "vsize-max-contiguous".
           let vsizes = actual.match(/vsize[^-]/g);
           let endOfBrowsers = actual.match(/End of Browser/g);
           if (endOfBrowsers == null) {
             endOfBrowsers = actual.match(/End of Web Content/g);
           }
-          let m2 = (vsizes.length == 4 && endOfBrowsers.length == 3);
+          let m2 = (vsizes.length == (4 + socketProcessRunning) &&
+                    endOfBrowsers.length == 3);
           ok(m2, "three child processes present in loaded data");
           good = good && !!m2;
 
           if (!good) {
             dump("*******ACTUAL*******\n");
             dump(actual);
             dump("********************\n");
           }
--- a/toolkit/components/aboutmemory/tests/test_memoryReporters.xul
+++ b/toolkit/components/aboutmemory/tests/test_memoryReporters.xul
@@ -135,16 +135,21 @@
     // file: URLs should have their path anonymized.
     if (reducedPath.search('file:..[^<]') !== -1) {
         present.unanonymizedFilePathWhenAnonymized = aPath;
     }
   }
 
   let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
             getService(Ci.nsIMemoryReporterManager);
+  let socketProcessRunning = 0;
+  if (SpecialPowers.getBoolPref("network.process.enabled")) {
+    socketProcessRunning = 1;
+  }
+
 
   let amounts = [
     "vsize",
     "vsizeMaxContiguous",
     "resident",
     "residentFast",
     "residentPeak",
     "residentUnique",
@@ -222,17 +227,18 @@
   {
     // Check the size is reasonable -- i.e. not ridiculously large or small.
     ok(100 * 1000 <= aAmount && aAmount <= 10 * 1000 * 1000 * 1000,
        aName + "'s size is reasonable");
   }
 
   function checkSpecialReport(aName, aAmounts, aCanBeUnreasonable)
   {
-    ok(aAmounts.length == 1, aName + " has " + aAmounts.length + " report");
+    ok(aAmounts.length == (1 + socketProcessRunning),
+       aName + " has " + aAmounts.length + " report");
     let n = aAmounts[0];
     if (!aCanBeUnreasonable) {
       checkSizeReasonable(aName, n);
     }
   }
 
   function checkResults()
   {
--- a/toolkit/components/aboutmemory/tests/test_memoryReporters2.xul
+++ b/toolkit/components/aboutmemory/tests/test_memoryReporters2.xul
@@ -13,35 +13,40 @@
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   </body>
 
   <!-- test code goes here -->
   <script type="application/javascript"><![CDATA[
 
   SimpleTest.waitForExplicitFinish();
+  let socketProcessRunning = 0;
+  if (SpecialPowers.getBoolPref("network.process.enabled")) {
+    socketProcessRunning = 1;
+  }
 
-  let numRemotes = 3;
+  let numToOpen = 3;
+  const expectedNumRemotes = numToOpen + socketProcessRunning;
   let numReady = 0;
 
   // Create some remote processes, and set up message-passing so that
   // we know when each child is fully initialized.
   let remotes = [];
   SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 3]]}, function() {
-    for (let i = 0; i < numRemotes; i++) {
+    for (let i = 0; i < numToOpen; i++) {
       let w = remotes[i] = window.open("remote.xul", "", "chrome");
 
       w.addEventListener("load", function loadHandler() {
         w.removeEventListener("load", loadHandler);
         let remoteBrowser = w.document.getElementById("remote");
         let mm = remoteBrowser.messageManager;
         mm.addMessageListener("test:ready", function readyHandler() {
           mm.removeMessageListener("test:ready", readyHandler);
           numReady++;
-          if (numReady == numRemotes) {
+          if (numReady == numToOpen) {
             // All the remote processes are ready.  Do memory reporting.
             doReports();
           }
         });
         mm.loadFrameScript("data:," + encodeURI("sendAsyncMessage('test:ready');"), true);
       });
     }
   });
@@ -66,37 +71,38 @@
       // getReports() has finished should silently abort.  (And the arguments
       // won't be used.)
       mgr.getReports(
         () => ok(false, "handleReport called for nested getReports() call"),
         null, null, null, /* anonymize = */ false
       );
 
       // Close the remote processes.
-      for (let i = 0; i < numRemotes; i++) {
+      for (let i = 0; i < numToOpen; i++) {
         remotes[i].close();
       }
 
       // Check the results.
 
       let processes = Object.keys(residents);
-      ok(processes.length == numRemotes + 1, "correct resident count");
+      ok(processes.length == expectedNumRemotes + 1, "correct resident count");
 
       let numEmptyProcesses = 0, numNonEmptyProcesses = 0;
       for (let i = 0; i < processes.length; i++) {
         if (processes[i] == "") {
           numEmptyProcesses++;
         } else {
-          ok(processes[i].startsWith("Browser (") || processes[i].startsWith("Web Content ("),
+          ok(processes[i].startsWith("Browser (") || processes[i].startsWith("Web Content (") ||
+             (processes[i].startsWith("SocketProcess") && socketProcessRunning),
              "correct non-empty process name prefix: " + processes[i]);
           numNonEmptyProcesses++;
         }
       }
       ok(numEmptyProcesses == 1, "correct empty process name count");
-      ok(numNonEmptyProcesses == numRemotes,
+      ok(numNonEmptyProcesses == expectedNumRemotes,
                                  "correct non-empty process name count");
 
       SimpleTest.finish();
     }
 
     mgr.getReports(handleReport, null, processReports, null,
                    /* anonymize = */ false);
   }
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1809,17 +1809,17 @@ nsresult nsMemoryReporterManager::StartG
   }
 
   if (RDDProcessManager* rdd = RDDProcessManager::Get()) {
     if (RefPtr<MemoryReportingProcess> proc = rdd->GetProcessMemoryReporter()) {
       s->mChildrenPending.AppendElement(proc.forget());
     }
   }
 
-  if (net::gIOService) {
+  if (!mIsRegistrationBlocked && net::gIOService) {
     if (RefPtr<MemoryReportingProcess> proc =
             net::gIOService->GetSocketProcessMemoryReporter()) {
       s->mChildrenPending.AppendElement(proc.forget());
     }
   }
 
   if (!s->mChildrenPending.IsEmpty()) {
     nsCOMPtr<nsITimer> timer;