Make test_0202_app_launch_apply_update_dirlocked.js as similar as possible to test_0202_app_launch_apply_update_dirlocked_svc.js - Bug 909489 - Intermittent test_0202_app_launch_apply_update_dirlocked.js | Test timed out | test failed (with xpcshell return code: 1). r=bbondy
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 05 Sep 2013 12:19:33 -0700
changeset 158796 c70f74b72e32f4a0bb47691523e048d18a5e54ca
parent 158795 09e0f4967a8968a248026fedf5d2063854f09ab8
child 158797 434147e2f000045b12aa78100a20e5f4f6fb5ee7
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy
bugs909489
milestone26.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
Make test_0202_app_launch_apply_update_dirlocked.js as similar as possible to test_0202_app_launch_apply_update_dirlocked_svc.js - Bug 909489 - Intermittent test_0202_app_launch_apply_update_dirlocked.js | Test timed out | test failed (with xpcshell return code: 1). r=bbondy
toolkit/mozapps/update/test/unit/head_update.js.in
toolkit/mozapps/update/test/unit/test_0200_app_launch_apply_update.js
toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js
toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js
toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js
toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js
toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js
toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js
toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js
--- a/toolkit/mozapps/update/test/unit/head_update.js.in
+++ b/toolkit/mozapps/update/test/unit/head_update.js.in
@@ -106,16 +106,22 @@ var gCallbackBinFile = "callback_app" + 
 var gCallbackArgs = ["./", "callback.log", "Test Arg 2", "Test Arg 3"];
 var gBackgroundUpdate = false;
 var gSwitchApp = false;
 var gDisableReplaceFallback = false;
 
 // Time to wait for the test helper process before continuing the test
 const TEST_HELPER_TIMEOUT = 100;
 
+// Time to wait for a check in the test before continuing the test
+const TEST_CHECK_TIMEOUT = 100;
+
+// How many of TEST_CHECK_TIMEOUT to wait before we abort the test.
+const MAX_TIMEOUT_RUNS = 300;
+
 // Use a copy of the main application executable for the test to avoid main
 // executable in use errors.
 const FILE_WIN_TEST_EXE = "_aus_test_app.exe";
 
 var gTestserver;
 
 var gXHR;
 var gXHRCallback;
@@ -1592,16 +1598,19 @@ function removeUpdater() {
       }
       catch (e) {
         logTestInfo("non-fatal error removing file after test finished (will " +
                     "try again). File: " + updater.path + " Exception: " + e);
         do_timeout(TEST_HELPER_TIMEOUT, removeUpdater);
         return;
       }
     }
+    else {
+      logTestInfo("updater doesn't exist, path: " + updater.path);
+    }
   }
   logTestInfo("calling do_test_finished");
   do_test_finished();
 }
 
 // Waits until files that are in use that break tests are no longer in use and
 // then calls removeCallbackCopy.
 function waitForFilesInUse() {
@@ -1623,28 +1632,28 @@ function waitForFilesInUse() {
           fileBak.remove(false);
         }
         file.copyTo(fileBak.parent, fileBak.leafName);
         file.remove(false);
         fileBak.moveTo(file.parent, file.leafName);
         logTestInfo("file is not in use. path: " + file.path);
       }
       catch (e) {
-        logTestInfo("file in use, will try again after " + CHECK_TIMEOUT_MILLI +
+        logTestInfo("file in use, will try again after " + TEST_CHECK_TIMEOUT +
                     " ms, path: " + file.path + ", exception: " + e);
         try {
           if (fileBak.exists()) {
             fileBak.remove(false);
           }
         }
         catch (e) {
           logTestInfo("unable to remove file, this should never happen! " +
                       "path: " + fileBak.path + ", exception: " + e);
         }
-        do_timeout(CHECK_TIMEOUT_MILLI, waitForFilesInUse);
+        do_timeout(TEST_CHECK_TIMEOUT, waitForFilesInUse);
         return;
       }
     }
   }
 
   removeCallbackCopy();
 }
 
@@ -2300,17 +2309,17 @@ let gProcessObserver = {
     logTestInfo("topic " + topic + ", process exitValue " + gProcess.exitValue);
     if (gAppTimer) {
       gAppTimer.cancel();
       gAppTimer = null;
     }
     if (topic != "process-finished" || gProcess.exitValue != 0) {
       do_throw("Failed to launch application");
     }
-    do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+    do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
   },
   QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIObserver])
 };
 
 /**
  * The timer callback to kill the process if it takes too long.
  */
 let gTimerCallback = {
--- a/toolkit/mozapps/update/test/unit/test_0200_app_launch_apply_update.js
+++ b/toolkit/mozapps/update/test/unit/test_0200_app_launch_apply_update.js
@@ -10,22 +10,16 @@
  */
 
 const TEST_ID = "0200";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 // Maximum number of milliseconds the process that is launched can run before
 // the test will try to kill it.
 const APP_TIMER_TIMEOUT = 120000;
 
 let gAppTimer;
 let gProcess;
 let gTimeoutRuns = 0;
 
@@ -230,45 +224,45 @@ function checkUpdateFinished() {
   updatesDir.append("0");
   let log = updatesDir.clone();
   log.append(FILE_UPDATE_LOG);
   if (!log.exists()) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates log to " +
                "be created at " + log.path);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   // Don't proceed until the update status is no longer pending or applying.
   let status = readStatusFile();
   if (status == STATE_PENDING || status == STATE_APPLYING) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates status " +
                "to not be pending or applying, current status is: " + status);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   // Don't proceed until the update.log file can be renamed to update.log.bak
   // (bug 889860).
   try {
     log.moveTo(updatesDir, FILE_UPDATE_LOG + ".bak");
   }
   catch (e) {
     logTestInfo("unable to rename file " + FILE_UPDATE_LOG + " to " +
                 FILE_UPDATE_LOG + ".bak. Exception: " + e);
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting to be able to " +
                "rename " + FILE_UPDATE_LOG + " to " + FILE_UPDATE_LOG +
                ".bak. Path: " + log.path);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   restoreLogFile();
 }
 
 /**
  * Checks if the renamed the update.log file can be renamed back to make
@@ -288,17 +282,17 @@ function restoreLogFile() {
   catch (e) {
     logTestInfo("unable to rename file " + FILE_UPDATE_LOG + ".bak back to " +
                 FILE_UPDATE_LOG + ". Exception: " + e);
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting to be able to " +
                "rename " + FILE_UPDATE_LOG + ".bak back to " + FILE_UPDATE_LOG +
                ". Path: " + log.path);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, restoreLogFile);
+      do_timeout(TEST_CHECK_TIMEOUT, restoreLogFile);
     return;
   }
 
   // Log the contents of the update.log so it is simpler to diagnose a test
   // failure. For example, on Windows if the application binary is in use the
   // updater will not apply the update.
   let contents = readFile(log);
   logTestInfo("contents of " + log.path + ":\n" +  
@@ -345,17 +339,17 @@ function checkLogRenameFinished() {
   let log = getUpdatesDir();
   log.append("0");
   log.append(FILE_UPDATE_LOG);
   if (log.exists()) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update log to " +
                "be renamed to last-update.log at " + log.path);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkLogRenameFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkLogRenameFinished);
     return;
   }
 
   let updatesDir = getUpdatesDir();
   log = updatesDir.clone();
   log.append("0");
   log.append(FILE_UPDATE_LOG);
   logTestInfo("testing " + log.path + " shouldn't exist");
--- a/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js
+++ b/toolkit/mozapps/update/test/unit/test_0201_app_launch_apply_update.js
@@ -13,22 +13,16 @@
  */
 
 const TEST_ID = "0201";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 // Maximum number of milliseconds the process that is launched can run before
 // the test will try to kill it.
 const APP_TIMER_TIMEOUT = 120000;
 
 let gAppTimer;
 let gProcess;
 let gActiveUpdate;
 let gTimeoutRuns = 0;
@@ -225,17 +219,17 @@ function checkUpdateApplied() {
   gTimeoutRuns++;
   // Don't proceed until the update has been applied.
   if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " +
                "applied, current state is: " +
                gUpdateManager.activeUpdate.state);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   let updatedDir = getAppDir();
   if (IS_MACOSX) {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
@@ -250,17 +244,17 @@ function checkUpdateApplied() {
     if (IS_MACOSX) {
       log.append("Contents");
       log.append("MacOS");
     }
     log.append("updates");
   }
   log.append(FILE_LAST_LOG);
   if (!log.exists()) {
-    do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+    do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   // Don't proceed until the update status is no longer pending or applying.
   let status = readStatusFile();
   do_check_eq(status, STATE_APPLIED_PLATFORM);
 
   // On Windows, make sure not to use the maintenance service for switching
@@ -348,51 +342,51 @@ function checkUpdateApplied() {
   logTestInfo("testing " + log.path + " shouldn't exist");
   do_check_false(log.exists());
 
   updatesDir.append("0");
   logTestInfo("testing " + updatesDir.path + " shouldn't exist");
   do_check_false(updatesDir.exists());
 
   // Now, switch the updated version of the app
-  do_timeout(CHECK_TIMEOUT_MILLI, switchApp);
+  do_timeout(TEST_CHECK_TIMEOUT, switchApp);
 }
 
 /**
  * Checks if the update has finished and if it has finished performs checks for
  * the test.
  */
 function checkUpdateFinished() {
   gTimeoutRuns++;
   // Don't proceed until the update status is no longer applied.
   try {
     let status = readStatusFile();
     if (status != STATE_SUCCEEDED) {
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " +
                  "change to succeeded, current status: " + status);
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     }
   } catch (e) {
     // Ignore exceptions if the status file is not found
   }
 
   try {
     // This will delete the app console log file if it exists.
     getAppConsoleLogPath();
   } catch (e) {
     if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) {
       // This might happen on Windows in case the callback application has not
       // finished its job yet.  So, we'll wait some more.
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded whilst waiting for file to be unlocked");
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     } else {
       do_throw("getAppConsoleLogPath threw: " + e);
     }
   }
 
   // At this point we need to see if the application was switched successfully.
 
@@ -401,17 +395,17 @@ function checkUpdateFinished() {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
   logTestInfo("testing " + updatedDir.path + " shouldn't exist");
   if (updatedDir.exists()) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded whilst waiting for update dir to not exist");
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   let updateTestDir = getUpdateTestDir();
 
   let file = updateTestDir.clone();
   file.append("UpdateTestRemoveFile");
   logTestInfo("testing " + file.path + " shouldn't exist");
--- a/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js
+++ b/toolkit/mozapps/update/test/unit/test_0202_app_launch_apply_update_dirlocked.js
@@ -19,20 +19,18 @@
  */
 
 const TEST_ID = "0202";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
 let gActiveUpdate;
+let gTimeoutRuns = 0;
 
 function run_test() {
   if (APP_BIN_NAME == "xulrunner") {
     logTestInfo("Unable to run this test on xulrunner");
     return;
   }
 
   if (IS_WIN) {
@@ -104,20 +102,16 @@ function run_test() {
                 ", exception: " + e);
   }
 
   let updatesPatchDir = getUpdatesDir();
   updatesPatchDir.append("0");
   let mar = do_get_file("data/simple.mar");
   mar.copyTo(updatesPatchDir, FILE_UPDATE_ARCHIVE);
 
-  reloadUpdateManagerData();
-  gActiveUpdate = gUpdateManager.activeUpdate;
-  do_check_true(!!gActiveUpdate);
-
   // Backup the updater.ini file if it exists by moving it. This prevents the
   // post update executable from being launched if it is specified.
   let updaterIni = processDir.clone();
   updaterIni.append(FILE_UPDATER_INI);
   if (updaterIni.exists()) {
     updaterIni.moveTo(processDir, FILE_UPDATER_INI_BAK);
   }
 
@@ -126,54 +120,64 @@ function run_test() {
   updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI);
   if (updateSettingsIni.exists()) {
     updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI_BAK);
   }
   updateSettingsIni = processDir.clone();
   updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI);
   writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS);
 
+  reloadUpdateManagerData();
+  gActiveUpdate = gUpdateManager.activeUpdate;
+  do_check_true(!!gActiveUpdate);
+
+  setEnvironment();
+
   // Initiate a background update.
   logTestInfo("update preparation completed - calling processUpdate");
   AUS_Cc["@mozilla.org/updates/update-processor;1"].
     createInstance(AUS_Ci.nsIUpdateProcessor).
     processUpdate(gActiveUpdate);
 
+  resetEnvironment();
+
   logTestInfo("processUpdate completed - calling checkUpdateApplied");
   checkUpdateApplied();
 }
 
 function end_test() {
   logTestInfo("start - test cleanup");
-  // Remove the files added by the update.
-  let updateTestDir = getUpdateTestDir();
-  try {
-    logTestInfo("removing update test directory " + updateTestDir.path);
-    removeDirRecursive(updateTestDir);
-  }
-  catch (e) {
-    logTestInfo("unable to remove directory - path: " + updateTestDir.path +
-                ", exception: " + e);
-  }
+  resetEnvironment();
 
   let processDir = getAppDir();
   // Restore the backup of the updater.ini if it exists.
   let updaterIni = processDir.clone();
   updaterIni.append(FILE_UPDATER_INI_BAK);
   if (updaterIni.exists()) {
     updaterIni.moveTo(processDir, FILE_UPDATER_INI);
   }
 
   // Restore the backed up updater-settings.ini if it exists.
   let updateSettingsIni = processDir.clone();
   updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI_BAK);
   if (updateSettingsIni.exists()) {
     updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI);
   }
 
+  // Remove the files added by the update.
+  let updateTestDir = getUpdateTestDir();
+  try {
+    logTestInfo("removing update test directory " + updateTestDir.path);
+    removeDirRecursive(updateTestDir);
+  }
+  catch (e) {
+    logTestInfo("unable to remove directory - path: " + updateTestDir.path +
+                ", exception: " + e);
+  }
+
   if (IS_UNIX) {
     // This will delete the launch script if it exists.
     getLaunchScript();
   }
 
   cleanUp();
   logTestInfo("finish - test cleanup");
 }
@@ -202,22 +206,27 @@ function getUpdateTestDir() {
 }
 
 /**
  * Checks if the update has failed being applied in the background.
  */
 function checkUpdateApplied() {
   // Don't proceed until the update has failed, and reset to pending.
   if (gUpdateManager.activeUpdate.state != STATE_PENDING) {
-    do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+    if (++gTimeoutRuns > MAX_TIMEOUT_RUNS)
+      do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for pending state to finish");
+    else
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
-  logTestInfo("update state equals " + gUpdateManager.activeUpdate.state);
+  do_timeout(TEST_CHECK_TIMEOUT, finishTest);
+}
 
+function finishTest() {
   // Don't proceed until the update status is pending.
   let status = readStatusFile();
   do_check_eq(status, STATE_PENDING);
 
   unlockDirectory(getAppDir());
 
   removeCallbackCopy();
 }
--- a/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js
+++ b/toolkit/mozapps/update/test/unit/test_0203_app_launch_apply_update.js
@@ -19,22 +19,16 @@
  */
 
 const TEST_ID = "0203";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 // Maximum number of milliseconds the process that is launched can run before
 // the test will try to kill it.
 const APP_TIMER_TIMEOUT = 120000;
 
 Components.utils.import("resource://gre/modules/ctypes.jsm");
 
 let gAppTimer;
 let gProcess;
@@ -253,17 +247,17 @@ function getUpdateTestDir() {
 function checkUpdateApplied() {
   gTimeoutRuns++;
   // Don't proceed until the update has been applied.
   if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " +
                "applied, current state is: " + gUpdateManager.activeUpdate.state);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   let updatedDir = getAppDir();
   if (IS_MACOSX) {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
@@ -278,17 +272,17 @@ function checkUpdateApplied() {
     if (IS_MACOSX) {
       log.append("Contents");
       log.append("MacOS");
     }
     log.append("updates");
   }
   log.append(FILE_LAST_LOG);
   if (!log.exists()) {
-    do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+    do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   // Don't proceed until the update status is no longer pending or applying.
   let status = readStatusFile();
   do_check_eq(status, STATE_APPLIED_PLATFORM);
 
   // On Windows, make sure not to use the maintenance service for switching
@@ -376,67 +370,67 @@ function checkUpdateApplied() {
   logTestInfo("testing " + log.path + " shouldn't exist");
   do_check_false(log.exists());
 
   updatesDir.append("0");
   logTestInfo("testing " + updatesDir.path + " shouldn't exist");
   do_check_false(updatesDir.exists());
 
   // Now, switch the updated version of the app
-  do_timeout(CHECK_TIMEOUT_MILLI, switchApp);
+  do_timeout(TEST_CHECK_TIMEOUT, switchApp);
 }
 
 /**
  * Checks if the update has finished and if it has finished performs checks for
  * the test.
  */
 function checkUpdateFinished() {
   // Don't proceed until the update status is no longer applied.
   gTimeoutRuns++;
   try {
     let status = readStatusFile();
     if (status != STATE_SUCCEEDED) {
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " +
                  "change to succeeded, current status: " + status);
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     }
   } catch (e) {
     // Ignore exceptions if the status file is not found
   }
 
   try {
     // This will delete the app console log file if it exists.
     getAppConsoleLogPath();
   } catch (e) {
     if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) {
       // This might happen on Windows in case the callback application has not
       // finished its job yet.  So, we'll wait some more.
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded whilst waiting for file to be unlocked");
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     } else {
       do_throw("getAppConsoleLogPath threw: " + e);
     }
   }
 
   // At this point we need to see if the application was switched successfully.
 
   let updatedDir = getAppDir();
   if (IS_MACOSX) {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
   logTestInfo("testing " + updatedDir.path + " shouldn't exist");
   if (updatedDir.exists()) {
-    do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+    do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   let updateTestDir = getUpdateTestDir();
 
   let file = updateTestDir.clone();
   file.append("UpdateTestRemoveFile");
   logTestInfo("testing " + file.path + " shouldn't exist");
--- a/toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js
+++ b/toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js
@@ -10,22 +10,16 @@
  */
 
 const TEST_ID = "0200_svc";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 let gTimeoutRuns = 0;
 
 function run_test() {
   if (!shouldRunServiceTest()) {
     return;
   }
 
   do_test_pending();
@@ -186,17 +180,17 @@ function checkUpdateFinished() {
   // Don't proceed until the update.log has been created.
   let log = getUpdatesDir();
   log.append("0");
   log.append(FILE_UPDATE_LOG);
   if (!log.exists()) {
     if (++gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates log to be created at " + log.path);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
     return;
   }
 
   // Log the contents of the update.log so it is simpler to diagnose a test
   // failure. For example, on Windows if the application binary is in use the
   // updater will not apply the update.
   let contents = readFile(log);
   logTestInfo("contents of " + log.path + ":\n" +  
--- a/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js
+++ b/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js
@@ -13,22 +13,16 @@
  */
 
 const TEST_ID = "0201_svc";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 // Maximum number of milliseconds the process that is launched can run before
 // the test will try to kill it.
 const APP_TIMER_TIMEOUT = 120000;
 
 let gAppTimer;
 let gProcess;
 let gActiveUpdate;
 let gTimeoutRuns = 0;
@@ -231,17 +225,17 @@ function checkUpdateApplied() {
   gTimeoutRuns++;
   // Don't proceed until the update has been applied.
   if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " +
                "applied, current state is: " +
                gUpdateManager.activeUpdate.state);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   let updatedDir = getAppDir();
   if (IS_MACOSX) {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
@@ -250,17 +244,17 @@ function checkUpdateApplied() {
 
   let log = getUpdatesDir();
   log.append(FILE_LAST_LOG);
   if (!log.exists()) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update log to " +
                "be created");
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   // Don't proceed until the update status is no longer pending or applying.
   let status = readStatusFile();
   do_check_eq(status, STATE_APPLIED_PLATFORM);
 
   // On Windows, make sure not to use the maintenance service for switching
@@ -329,51 +323,51 @@ function checkUpdateApplied() {
   logTestInfo("testing " + log.path + " shouldn't exist");
   do_check_false(log.exists());
 
   updatesDir.append("0");
   logTestInfo("testing " + updatesDir.path + " shouldn't exist");
   do_check_false(updatesDir.exists());
 
   // Now, switch the updated version of the app
-  do_timeout(CHECK_TIMEOUT_MILLI, switchApp);
+  do_timeout(TEST_CHECK_TIMEOUT, switchApp);
 }
 
 /**
  * Checks if the update has finished and if it has finished performs checks for
  * the test.
  */
 function checkUpdateFinished() {
   gTimeoutRuns++;
   // Don't proceed until the update status is no longer applied.
   try {
     let status = readStatusFile();
     if (status != STATE_SUCCEEDED) {
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " +
                  "change to succeeded, current status: " + status);
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     }
   } catch (e) {
     // Ignore exceptions if the status file is not found
   }
 
   try {
     // This will delete the app console log file if it exists.
     getAppConsoleLogPath();
   } catch (e) {
     if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) {
       // This might happen on Windows in case the callback application has not
       // finished its job yet.  So, we'll wait some more.
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded whilst waiting for file to be unlocked");
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     } else {
       do_throw("getAppConsoleLogPath threw: " + e);
     }
   }
 
   // At this point we need to see if the application was switched successfully.
 
--- a/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js
+++ b/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js
@@ -19,22 +19,16 @@
  */
 
 const TEST_ID = "0202_svc";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 let gActiveUpdate;
 let gTimeoutRuns = 0;
 
 function run_test() {
   if (!shouldRunServiceTest()) {
     return;
   }
 
@@ -197,21 +191,21 @@ function getUpdateTestDir() {
  * Checks if the update has failed being applied in the background.
  */
 function checkUpdateApplied() {
   // Don't proceed until the update has failed, and reset to pending.
   if (gUpdateManager.activeUpdate.state != STATE_PENDING) {
     if (++gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for pending state to finish");
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
-  do_timeout(CHECK_TIMEOUT_MILLI, finishTest);
+  do_timeout(TEST_CHECK_TIMEOUT, finishTest);
 }
 
 function finishTest() {
   // Don't proceed until the update status is pending.
   let status = readStatusFile();
   do_check_eq(status, STATE_PENDING);
 
   unlockDirectory(getAppDir());
--- a/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js
+++ b/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js
@@ -19,22 +19,16 @@
  */
 
 const TEST_ID = "0203_svc";
 
 // Backup the updater.ini and use a custom one to prevent the updater from
 // launching a post update executable.
 const FILE_UPDATER_INI_BAK = "updater.ini.bak";
 
-// Number of milliseconds for each do_timeout call.
-const CHECK_TIMEOUT_MILLI = 1000;
-
-// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test.
-const MAX_TIMEOUT_RUNS = 300;
-
 // Maximum number of milliseconds the process that is launched can run before
 // the test will try to kill it.
 const APP_TIMER_TIMEOUT = 120000;
 
 Components.utils.import("resource://gre/modules/ctypes.jsm");
 
 let gAppTimer;
 let gProcess;
@@ -256,17 +250,17 @@ function getUpdateTestDir() {
 function checkUpdateApplied() {
   gTimeoutRuns++;
   // Don't proceed until the update has been applied.
   if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " +
                "applied, current state is: " + gUpdateManager.activeUpdate.state);
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   let updatedDir = getAppDir();
   if (IS_MACOSX) {
     updatedDir = updatedDir.parent.parent;
   }
   updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", ""));
@@ -275,17 +269,17 @@ function checkUpdateApplied() {
 
   let log = getUpdatesDir();
   log.append(FILE_LAST_LOG);
   if (!log.exists()) {
     if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
       do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for update log to be " +
                "created");
     else
-      do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied);
+      do_timeout(TEST_CHECK_TIMEOUT, checkUpdateApplied);
     return;
   }
 
   // Don't proceed until the update status is no longer pending or applying.
   let status = readStatusFile();
   do_check_eq(status, STATE_APPLIED_PLATFORM);
 
   // On Windows, make sure not to use the maintenance service for switching
@@ -354,34 +348,34 @@ function checkUpdateApplied() {
   logTestInfo("testing " + log.path + " shouldn't exist");
   do_check_false(log.exists());
 
   updatesDir.append("0");
   logTestInfo("testing " + updatesDir.path + " shouldn't exist");
   do_check_false(updatesDir.exists());
 
   // Now, switch the updated version of the app
-  do_timeout(CHECK_TIMEOUT_MILLI, switchApp);
+  do_timeout(TEST_CHECK_TIMEOUT, switchApp);
 }
 
 /**
  * Checks if the update has finished and if it has finished performs checks for
  * the test.
  */
 function checkUpdateFinished() {
   gTimeoutRuns++;
   // Don't proceed until the update status is no longer applied.
   try {
     let status = readStatusFile();
     if (status != STATE_SUCCEEDED) {
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " +
                  "change to succeeded, current status: " + status);
       else
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     }
   } catch (e) {
     // Ignore exceptions if the status file is not found
   }
 
   try {
     // This will delete the app console log file if it exists.
@@ -389,17 +383,17 @@ function checkUpdateFinished() {
   } catch (e) {
     if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) {
       if (gTimeoutRuns > MAX_TIMEOUT_RUNS)
         do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for file to be " +
                  "unlocked");
       else
         // This might happen on Windows in case the callback application has not
         // finished its job yet.  So, we'll wait some more.
-        do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished);
+        do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
       return;
     } else {
       do_throw("getAppConsoleLogPath threw: " + e);
     }
   }
 
   // At this point we need to see if the application was switched successfully.