Bug 888550 - Use a dynamic port in search/ xpcshell tests so they can be run in parallel. r=MattN
authorMihnea Dobrescu-Balaur <mihneadb@gmail.com>
Tue, 09 Jul 2013 10:46:25 -0700
changeset 137981 82afb38d2b141186436a0541494b1a641fe2accc
parent 137980 d5720a99657f9c103579ab7a51c8494f62fa9c3b
child 137982 fef3c4558c3c06210d99bab474edcb02dab42787
push id30766
push userryanvm@gmail.com
push dateWed, 10 Jul 2013 14:07:47 +0000
treeherdermozilla-inbound@fef3c4558c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs888550
milestone25.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 888550 - Use a dynamic port in search/ xpcshell tests so they can be run in parallel. r=MattN
toolkit/components/search/tests/xpcshell/test_addEngine_callback.js
toolkit/components/search/tests/xpcshell/test_defaultEngine.js
toolkit/components/search/tests/xpcshell/test_nocache.js
toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js
toolkit/components/search/tests/xpcshell/test_notifications.js
toolkit/components/search/tests/xpcshell/test_prefSync.js
toolkit/components/search/tests/xpcshell/test_purpose.js
toolkit/components/search/tests/xpcshell/test_save_sorted_engines.js
--- a/toolkit/components/search/tests/xpcshell/test_addEngine_callback.js
+++ b/toolkit/components/search/tests/xpcshell/test_addEngine_callback.js
@@ -3,16 +3,18 @@
 
 /*
  * Tests covering nsIBrowserSearchService::addEngine's optional callback.
  */
 
 "use strict";
 
 const Ci = Components.interfaces;
+let gHttpServer;
+let gBaseUrl;
 
 Components.utils.import("resource://testing-common/httpd.js");
 
 // Override the prompt service and nsIPrompt, since the search service currently
 // prompts in response to certain installation failures we test here
 // XXX this should disappear once bug 863474 is fixed
 function replaceService(contractID, component) {
   let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
@@ -62,17 +64,17 @@ add_test(function simple_callback_test()
       do_check_true(!!engine);
       do_check_neq(engine.name, Services.search.defaultEngine.name);
       run_next_test();
     },
     onError: function (errorCode) {
       do_throw("search callback returned error: " + errorCode);
     }
   }
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine(gBaseUrl + "/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false, searchCallback);
 });
 
 // Test of the search callback on duplicate engine failures
 add_test(function duplicate_failure_test() {
   let searchCallback = {
     onSuccess: function (engine) {
@@ -80,17 +82,17 @@ add_test(function duplicate_failure_test
     },
     onError: function (errorCode) {
       do_check_true(!!errorCode);
       do_check_eq(errorCode, Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE);
       run_next_test();
     }
   }
   // Re-add the same engine added in the previous test
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine(gBaseUrl + "/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false, searchCallback);
 });
 
 // Test of the search callback on failure to load the engine failures
 add_test(function load_failure_test() {
   let searchCallback = {
     onSuccess: function (engine) {
@@ -106,18 +108,19 @@ add_test(function load_failure_test() {
   Services.search.addEngine("http://invalid/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false, searchCallback);
 });
 
 function run_test() {
   updateAppInfo();
 
-  let httpServer = new HttpServer();
-  httpServer.start(4444);
-  httpServer.registerDirectory("/", do_get_cwd());
+  gHttpServer = new HttpServer();
+  gHttpServer.start(-1);
+  gHttpServer.registerDirectory("/", do_get_cwd());
+  gBaseUrl = "http://localhost:" + gHttpServer.identity.primaryPort;
 
   do_register_cleanup(function cleanup() {
-    httpServer.stop(function() {});
+    gHttpServer.stop(function() {});
   });
 
   run_next_test();
 }
--- a/toolkit/components/search/tests/xpcshell/test_defaultEngine.js
+++ b/toolkit/components/search/tests/xpcshell/test_defaultEngine.js
@@ -72,27 +72,28 @@ function search_observer(aSubject, aTopi
   do_test_finished();
 }
 
 function run_test() {
   removeMetadata();
   updateAppInfo();
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
+  let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
 
   do_register_cleanup(function cleanup() {
     httpServer.stop(function() {});
     Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
   });
 
   do_test_pending();
 
   Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
 
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine(baseUrl + "/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false);
-  Services.search.addEngine("http://localhost:4444/data/engine2.xml",
+  Services.search.addEngine(baseUrl + "/data/engine2.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false);
 }
--- a/toolkit/components/search/tests/xpcshell/test_nocache.js
+++ b/toolkit/components/search/tests/xpcshell/test_nocache.js
@@ -20,17 +20,17 @@ Cu.import("resource://testing-common/htt
 
 function run_test()
 {
   removeCache();
   updateAppInfo();
   do_load_manifest("data/chrome.manifest");
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
 
   let search = Services.search;
 
   do_test_pending();
 
   // Check that cache is created at startup
   afterCache(function cacheCreated() {
@@ -88,13 +88,14 @@ function run_test()
             }
           });
         });
       }
     };
     Services.obs.addObserver(observer, "browser-search-engine-modified", false);
 
     // Add an engine, check if it appears in the cache
-    search.addEngine("http://localhost:4444/data/engine.xml",
-                   Ci.nsISearchEngine.DATA_XML,
-                   null, false);
+    search.addEngine("http://localhost:" + httpServer.identity.primaryPort +
+                     "/data/engine.xml",
+                     Ci.nsISearchEngine.DATA_XML,
+                     null, false);
   });
 }
--- a/toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js
+++ b/toolkit/components/search/tests/xpcshell/test_nodb_pluschanges.js
@@ -30,18 +30,19 @@ Cu.import("resource://testing-common/htt
 function run_test()
 {
   do_print("Preparing test");
   removeMetadata();
   updateAppInfo();
   do_load_manifest("data/chrome.manifest");
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
+  let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
 
   let search = Services.search;
 
   do_print("Setting up observer");
   function observer(aSubject, aTopic, aData) {
     do_print("Observing topic " + aTopic);
     if ("engine-added" == aData) {
       let engine1 = search.getEngineByName("Test search engine");
@@ -88,20 +89,20 @@ function run_test()
       }
     }
   };
   Services.obs.addObserver(observer, "browser-search-engine-modified",
                            false);
 
   do_test_pending();
 
-  search.addEngine("http://localhost:4444/data/engine.xml",
+  search.addEngine(baseUrl + "/data/engine.xml",
                    Ci.nsISearchEngine.DATA_XML,
                    null, false);
-  search.addEngine("http://localhost:4444/data/engine.src",
+  search.addEngine(baseUrl + "/data/engine.src",
                    Ci.nsISearchEngine.DATA_TEXT,
-                   "http://localhost:4444/data/ico-size-16x16-png.ico",
+                   baseUrl + "/data/ico-size-16x16-png.ico",
                    false);
 
   do_timeout(120000, function() {
     do_throw("Timeout");
   });
 }
--- a/toolkit/components/search/tests/xpcshell/test_notifications.js
+++ b/toolkit/components/search/tests/xpcshell/test_notifications.js
@@ -59,24 +59,26 @@ function search_observer(subject, topic,
   }
 }
 
 function run_test() {
   removeMetadata();
   updateAppInfo();
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
 
   do_register_cleanup(function cleanup() {
     httpServer.stop(function() {});
     Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
   });
 
   do_test_pending();
 
   Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
 
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine("http://localhost:" +
+                            httpServer.identity.primaryPort +
+                            "/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false);
 }
--- a/toolkit/components/search/tests/xpcshell/test_prefSync.js
+++ b/toolkit/components/search/tests/xpcshell/test_prefSync.js
@@ -103,27 +103,28 @@ function search_observer(aSubject, aTopi
   do_test_finished();
 }
 
 function run_test() {
   removeMetadata();
   updateAppInfo();
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
+  let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
 
   do_register_cleanup(function cleanup() {
     httpServer.stop(function() {});
     Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
   });
 
   do_test_pending();
 
   Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
 
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine(baseUrl + "/data/engine.xml",
                    Ci.nsISearchEngine.DATA_XML,
                    null, false);
-  Services.search.addEngine("http://localhost:4444/data/engine2.xml",
+  Services.search.addEngine(baseUrl + "/data/engine2.xml",
                    Ci.nsISearchEngine.DATA_XML,
                    null, false);
 }
--- a/toolkit/components/search/tests/xpcshell/test_purpose.js
+++ b/toolkit/components/search/tests/xpcshell/test_purpose.js
@@ -50,23 +50,25 @@ function search_observer(aSubject, aTopi
 };
 
 function run_test() {
   removeMetadata();
   updateAppInfo();
   do_load_manifest("data/chrome.manifest");
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
 
   do_register_cleanup(function cleanup() {
     httpServer.stop(function() {});
     Services.obs.removeObserver(search_observer, "browser-search-engine-modified");
   });
 
   do_test_pending();
   Services.obs.addObserver(search_observer, "browser-search-engine-modified", false);
 
-  Services.search.addEngine("http://localhost:4444/data/engine.xml",
+  Services.search.addEngine("http://localhost:" +
+                            httpServer.identity.primaryPort +
+                            "/data/engine.xml",
                             Ci.nsISearchEngine.DATA_XML,
                             null, false);
 }
--- a/toolkit/components/search/tests/xpcshell/test_save_sorted_engines.js
+++ b/toolkit/components/search/tests/xpcshell/test_save_sorted_engines.js
@@ -25,18 +25,19 @@ const Cr = Components.results;
 Cu.import("resource://testing-common/httpd.js");
 
 function run_test() {
   do_print("Preparing test");
   removeMetadata();
   updateAppInfo();
 
   let httpServer = new HttpServer();
-  httpServer.start(4444);
+  httpServer.start(-1);
   httpServer.registerDirectory("/", do_get_cwd());
+  let baseUrl = "http://localhost:" + httpServer.identity.primaryPort;
 
   function getSearchMetadata() {
     // Check that search-metadata.json has been created
     let metadata = gProfD.clone();
     metadata.append("search-metadata.json");
     do_check_true(metadata.exists());
 
     let stream = NetUtil.newChannel(metadata).open();
@@ -104,20 +105,20 @@ function run_test() {
         });
       });
     });
   };
   Services.obs.addObserver(observer, "browser-search-engine-modified", false);
 
   do_test_pending();
 
-  search.addEngine("http://localhost:4444/data/engine.xml",
+  search.addEngine(baseUrl + "/data/engine.xml",
                    Ci.nsISearchEngine.DATA_XML,
                    null, false);
-  search.addEngine("http://localhost:4444/data/engine.src",
+  search.addEngine(baseUrl + "/data/engine.src",
                    Ci.nsISearchEngine.DATA_TEXT,
-                   "http://localhost:4444/data/ico-size-16x16-png.ico",
+                   baseUrl + "/data/ico-size-16x16-png.ico",
                    false);
 
   do_timeout(120000, function() {
     do_throw("Timeout");
   });
 }