Bug 1230027 - Stop burnCPOWInSandbox from being GC'd during tests. r?yoric draft
authorSami Jaktholm <sjakthol@outlook.com>
Tue, 22 Dec 2015 20:15:17 +0200
changeset 317184 6097a08d1db6d147a0682b11a905c11325106363
parent 317010 3cc8559d0d65d5704eedc72238a82c09b4b630cd
child 512269 ba57509ffe74644d02ba639fd4f283aad85a2ed9
push id8667
push usersjakthol@outlook.com
push dateWed, 23 Dec 2015 06:06:48 +0000
reviewersyoric
bugs1230027
milestone46.0a1
Bug 1230027 - Stop burnCPOWInSandbox from being GC'd during tests. r?yoric Since no one is holding a reference to the burnCPOWInSandbox function in the child process, it might get GC'd during the test. Binding it to the global object should keep the function alive long enough for the test to call it via CPOW.
toolkit/components/perfmonitoring/tests/browser/head.js
--- a/toolkit/components/perfmonitoring/tests/browser/head.js
+++ b/toolkit/components/perfmonitoring/tests/browser/head.js
@@ -88,25 +88,29 @@ CPUBurner.frameScript = function() {
           sendAsyncMessage(topic, {});
         } catch (ex) {
           dump(`This is the content attempting to burn CPU: error ${ex}\n`);
           dump(`${ex.stack}\n`);
         }
       });
     }
 
+    // Bind the function to the global context or it might be GC'd during test
+    // causing failures (bug 1230027)
+    this.burnCPOWInSandbox = function(addonId) {
+      try {
+        burnCPUInSandbox(addonId);
+      } catch (ex) {
+        dump(`This is the addon attempting to burn CPOW: error ${ex}\n`);
+        dump(`${ex.stack}\n`);
+      }
+    }
+
     sendAsyncMessage("test-performance-watcher:cpow-init", {}, {
-      burnCPOWInSandbox: function(addonId) {
-        try {
-          burnCPUInSandbox(addonId);
-        } catch (ex) {
-          dump(`This is the addon attempting to burn CPOW: error ${ex}\n`);
-          dump(`${ex.stack}\n`);
-        }
-      }
+      burnCPOWInSandbox: this.burnCPOWInSandbox
     });
 
   } catch (ex) {
     Cu.reportError("This is the addon: error " + ex);
     Cu.reportError(ex.stack);
   }
 };