Bug 872379 - Netmonitor tests SJS: Store a reference to the response timer to avoid garbage collection before the timer fires. Otherwise netmonitor tests timeout waiting for missing responses. r=vp, a=test-only
authorSami Jaktholm <sjakthol@outlook.com>
Mon, 30 Jun 2014 03:09:00 -0400
changeset 208606 db17a0748b2d040fd8f1f8d88f547a59682be008
parent 208605 4851cd40200f9d6cc7aa56b04e6bac4ab5a71a7b
child 208607 547deb189c6fca55f79990c07bd4570f8fd5346c
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvp, test-only
bugs872379
milestone32.0a2
Bug 872379 - Netmonitor tests SJS: Store a reference to the response timer to avoid garbage collection before the timer fires. Otherwise netmonitor tests timeout waiting for missing responses. r=vp, a=test-only
browser/devtools/netmonitor/test/sjs_content-type-test-server.sjs
browser/devtools/netmonitor/test/sjs_sorting-test-server.sjs
browser/devtools/netmonitor/test/sjs_status-codes-test-server.sjs
--- a/browser/devtools/netmonitor/test/sjs_content-type-test-server.sjs
+++ b/browser/devtools/netmonitor/test/sjs_content-type-test-server.sjs
@@ -21,17 +21,20 @@ function handleRequest(request, response
     if (cachedCount % 2) {
       response.setHeader("Cache-Control", "max-age=" + cacheExpire, false);
     } else {
       response.setHeader("Expires", Date(Date.now() + cacheExpire * 1000), false);
     }
     cachedCount++;
   }
 
-  Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer).initWithCallback(() => {
+  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+  timer.initWithCallback(() => {
+    // to avoid garbage collection
+    timer = null;
     switch (format) {
       case "txt": {
         response.setStatusLine(request.httpVersion, status, "DA DA DA");
         response.setHeader("Content-Type", "text/plain", false);
         maybeMakeCached();
         response.write("Братан, ты вообще качаешься?");
         response.finish();
         break;
--- a/browser/devtools/netmonitor/test/sjs_sorting-test-server.sjs
+++ b/browser/devtools/netmonitor/test/sjs_sorting-test-server.sjs
@@ -4,15 +4,18 @@
 const { classes: Cc, interfaces: Ci } = Components;
 
 function handleRequest(request, response) {
   response.processAsync();
 
   let params = request.queryString.split("&");
   let index = params.filter((s) => s.contains("index="))[0].split("=")[1];
 
-  Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer).initWithCallback(() => {
+  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+  timer.initWithCallback(() => {
+    // to avoid garbage collection
+    timer = null;
     response.setStatusLine(request.httpVersion, index == 1 ? 101 : index * 100, "Meh");
     response.setHeader("Content-Type", "text/" + index, false);
     response.write(new Array(index * 10).join(index)); // + 0.01 KB
     response.finish();
   }, 10, Ci.nsITimer.TYPE_ONE_SHOT); // Make sure this request takes a few ms.
 }
--- a/browser/devtools/netmonitor/test/sjs_status-codes-test-server.sjs
+++ b/browser/devtools/netmonitor/test/sjs_status-codes-test-server.sjs
@@ -4,17 +4,20 @@
 const { classes: Cc, interfaces: Ci } = Components;
 
 function handleRequest(request, response) {
   response.processAsync();
 
   let params = request.queryString.split("&");
   let status = params.filter((s) => s.contains("sts="))[0].split("=")[1];
 
-  Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer).initWithCallback(() => {
+  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+  timer.initWithCallback(() => {
+    // to avoid garbage collection
+    timer = null;
     switch (status) {
       case "100":
         response.setStatusLine(request.httpVersion, 101, "Switching Protocols");
         break;
       case "200":
         response.setStatusLine(request.httpVersion, 202, "Created");
         break;
       case "300":