Bug 1311739 - Fail push tests with an informative error if the H/2 server port is missing. r=dragana
authorKit Cambridge <kit@yakshaving.ninja>
Thu, 20 Oct 2016 09:25:36 -0700
changeset 364278 357a4a25901a9269c90a1dd09010c16d50ad8c72
parent 364277 d2b9b6e2da6b76e7d5134980fb02f31cdaf6eca4
child 364279 c0c3b590372cef550c27b4ac24867bd491134e09
push id1369
push userjlorenzo@mozilla.com
push dateMon, 27 Feb 2017 14:59:41 +0000
treeherdermozilla-release@d75a1dba431f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1311739
milestone52.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 1311739 - Fail push tests with an informative error if the H/2 server port is missing. r=dragana MozReview-Commit-ID: 97rOKjbDlTu
dom/push/test/xpcshell/head-http2.js
dom/push/test/xpcshell/test_notification_http2.js
dom/push/test/xpcshell/test_register_error_http2.js
dom/push/test/xpcshell/test_register_success_http2.js
dom/push/test/xpcshell/test_registration_success_http2.js
dom/push/test/xpcshell/test_unregister_success_http2.js
--- a/dom/push/test/xpcshell/head-http2.js
+++ b/dom/push/test/xpcshell/head-http2.js
@@ -1,8 +1,19 @@
+// Returns the test H/2 server port, throwing if it's missing or invalid.
+function getTestServerPort() {
+  let portEnv = Cc["@mozilla.org/process/environment;1"]
+                  .getService(Ci.nsIEnvironment).get("MOZHTTP2_PORT");
+  let port = parseInt(portEnv, 10);
+  if (!Number.isFinite(port) || port < 1 || port > 65535) {
+    throw new Error(`Invalid port in MOZHTTP2_PORT env var: ${portEnv}`);
+  }
+  do_print(`Using HTTP/2 server on port ${port}`);
+  return port;
+}
 
 // Support for making sure we can talk to the invalid cert the server presents
 var CertOverrideListener = function(host, port, bits) {
   this.host = host;
   this.port = port || 443;
   this.bits = bits;
 };
 
--- a/dom/push/test/xpcshell/test_notification_http2.js
+++ b/dom/push/test/xpcshell/test_notification_http2.js
@@ -8,20 +8,17 @@ Cu.import("resource://gre/modules/Servic
 const {PushDB, PushService, PushServiceHttp2} = serviceExports;
 
 var prefs;
 var tlsProfile;
 
 var serverPort = -1;
 
 function run_test() {
-  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-  serverPort = env.get("MOZHTTP2_PORT");
-  do_check_neq(serverPort, null);
-  dump("using port " + serverPort + "\n");
+  serverPort = getTestServerPort();
 
   do_get_profile();
   setPrefs({
     'testing.allowInsecureServerURL': true,
   });
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   tlsProfile = prefs.getBoolPref("network.http.spdy.enforce-tls-profile");
--- a/dom/push/test/xpcshell/test_register_error_http2.js
+++ b/dom/push/test/xpcshell/test_register_error_http2.js
@@ -9,19 +9,17 @@ const {PushDB, PushService, PushServiceH
 
 var prefs;
 var tlsProfile;
 var serverURL;
 
 var serverPort = -1;
 
 function run_test() {
-  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-  serverPort = env.get("MOZHTTP2_PORT");
-  do_check_neq(serverPort, null);
+  serverPort = getTestServerPort();
 
   do_get_profile();
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   tlsProfile = prefs.getBoolPref("network.http.spdy.enforce-tls-profile");
 
   serverURL = "https://localhost:" + serverPort;
 
--- a/dom/push/test/xpcshell/test_register_success_http2.js
+++ b/dom/push/test/xpcshell/test_register_success_http2.js
@@ -11,19 +11,17 @@ var prefs;
 var tlsProfile;
 var serverURL;
 var serverPort = -1;
 var pushEnabled;
 var pushConnectionEnabled;
 var db;
 
 function run_test() {
-  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-  serverPort = env.get("MOZHTTP2_PORT");
-  do_check_neq(serverPort, null);
+  serverPort = getTestServerPort();
 
   do_get_profile();
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   tlsProfile = prefs.getBoolPref("network.http.spdy.enforce-tls-profile");
   pushEnabled = prefs.getBoolPref("dom.push.enabled");
   pushConnectionEnabled = prefs.getBoolPref("dom.push.connection.enabled");
 
--- a/dom/push/test/xpcshell/test_registration_success_http2.js
+++ b/dom/push/test/xpcshell/test_registration_success_http2.js
@@ -16,19 +16,17 @@ PromiseTestUtils.thisTestLeaksUncaughtRe
 
 const {PushDB, PushService, PushServiceHttp2} = serviceExports;
 
 var prefs;
 
 var serverPort = -1;
 
 function run_test() {
-  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-  serverPort = env.get("MOZHTTP2_PORT");
-  do_check_neq(serverPort, null);
+  serverPort = getTestServerPort();
 
   do_get_profile();
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   run_next_test();
 }
 
 add_task(function* test_pushNotifications() {
--- a/dom/push/test/xpcshell/test_unregister_success_http2.js
+++ b/dom/push/test/xpcshell/test_unregister_success_http2.js
@@ -19,19 +19,17 @@ const {PushDB, PushService, PushServiceH
 var prefs;
 var tlsProfile;
 var pushEnabled;
 var pushConnectionEnabled;
 
 var serverPort = -1;
 
 function run_test() {
-  var env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
-  serverPort = env.get("MOZHTTP2_PORT");
-  do_check_neq(serverPort, null);
+  serverPort = getTestServerPort();
 
   do_get_profile();
   prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
 
   tlsProfile = prefs.getBoolPref("network.http.spdy.enforce-tls-profile");
   pushEnabled = prefs.getBoolPref("dom.push.enabled");
   pushConnectionEnabled = prefs.getBoolPref("dom.push.connection.enabled");