diff --git 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 index 2a9cd78a566..5d5dffd1738 100644 --- 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 @@ -18,12 +18,16 @@ 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 = 15000; let gAppTimer; let gProcess; +let gTimeoutRuns = 0; function run_test() { do_test_pending(); @@ -236,19 +240,26 @@ function getUpdateTestDir() { * the test. */ function checkUpdateFinished() { + gTimeoutRuns++; // Don't proceed until the update.log has been created. let log = getUpdatesDir(); log.append("0"); log.append(FILE_UPDATE_LOG); if (!log.exists()) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates log to be created"); + else + do_timeout(CHECK_TIMEOUT_MILLI, 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) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates status to not be pending or applying"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } diff --git 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 index 74b7a0a3c08..8b68250d08d 100644 --- 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 @@ -21,6 +21,9 @@ 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 = 15000; @@ -28,6 +31,7 @@ const APP_TIMER_TIMEOUT = 15000; let gAppTimer; let gProcess; let gActiveUpdate; +let gTimeoutRuns = 0; // Override getUpdatesRootDir on Mac because we need to apply the update // inside the bundle directory. @@ -327,9 +331,13 @@ function getUpdateTestDir() { * Checks if the update has finished being applied in the background. */ function checkUpdateApplied() { + gTimeoutRuns++; // Don't proceed until the update has been applied. if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be applied"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); return; } @@ -459,11 +467,15 @@ function checkUpdateApplied() { * the test. */ function checkUpdateFinished() { + gTimeoutRuns++; // Don't proceed until the update status is no longer applied. try { let status = readStatusFile(); if (status != STATE_SUCCEEDED) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for succeeded state"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } } catch (e) { @@ -477,7 +489,10 @@ function checkUpdateFinished() { 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. - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for file to be unlocked"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } else { do_throw("getAppConsoleLogPath threw: " + e); @@ -493,7 +508,10 @@ function checkUpdateFinished() { updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); logTestInfo("testing " + updatedDir.path + " shouldn't exist"); if (updatedDir.exists()) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for update dir to not exist"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } diff --git 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 index 16f57d09775..43b18288a5e 100644 --- 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 @@ -27,6 +27,8 @@ const FILE_UPDATER_INI_BAK = "updater.ini.bak"; // Number of milliseconds for each do_timeout call. const CHECK_TIMEOUT_MILLI = 1000; +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 = 15000; @@ -36,6 +38,7 @@ Components.utils.import("resource://gre/modules/ctypes.jsm"); let gAppTimer; let gProcess; let gActiveUpdate; +let gTimeoutRuns = 0; // Override getUpdatesRootDir on Mac because we need to apply the update // inside the bundle directory. @@ -356,9 +359,13 @@ function getUpdateTestDir() { * Checks if the update has finished being applied in the background. */ function checkUpdateApplied() { + gTimeoutRuns++; // Don't proceed until the update has been applied. if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for update to be applied"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); return; } @@ -489,10 +496,14 @@ function checkUpdateApplied() { */ function checkUpdateFinished() { // Don't proceed until the update status is no longer applied. + gTimeoutRuns++; try { let status = readStatusFile(); if (status != STATE_SUCCEEDED) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for succeeded state"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } } catch (e) { @@ -506,7 +517,10 @@ function checkUpdateFinished() { 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. - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for file to be unlocked"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } else { do_throw("getAppConsoleLogPath threw: " + e); diff --git 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 index 1c9ffedb312..ab25c45f2b2 100644 --- 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 @@ -18,10 +18,15 @@ 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 = 15000; +let gTimeoutRuns = 0; + function run_test() { if (!shouldRunServiceTest()) { return; @@ -198,7 +203,10 @@ function checkUpdateFinished() { log.append("0"); log.append(FILE_UPDATE_LOG); if (!log.exists()) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates log to be created"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } diff --git 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 index 73e9c04fc45..a44ba361098 100644 --- 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 @@ -21,6 +21,9 @@ 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 = 15000; @@ -28,6 +31,7 @@ const APP_TIMER_TIMEOUT = 15000; let gAppTimer; let gProcess; let gActiveUpdate; +let gTimeoutRuns = 0; // Override getUpdatesRootDir on Mac because we need to apply the update // inside the bundle directory. @@ -335,9 +339,13 @@ function getUpdateTestDir() { * Checks if the update has finished being applied in the background. */ function checkUpdateApplied() { + gTimeoutRuns++; // Don't proceed until the update has been applied. if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to be applied to platform"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); return; } @@ -352,7 +360,10 @@ function checkUpdateApplied() { let log = getUpdatesDir(); log.append(FILE_LAST_LOG); if (!log.exists()) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + 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); return; } @@ -439,11 +450,15 @@ function checkUpdateApplied() { * the test. */ function checkUpdateFinished() { + gTimeoutRuns++; // Don't proceed until the update status is no longer applied. try { let status = readStatusFile(); if (status != STATE_SUCCEEDED) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for succeeded state"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } } catch (e) { @@ -457,7 +472,10 @@ function checkUpdateFinished() { 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. - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded whilst waiting for file to be unlocked"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } else { do_throw("getAppConsoleLogPath threw: " + e); diff --git 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 index 021533c10f5..7f58b9b2fa1 100644 --- 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 @@ -27,11 +27,15 @@ 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 = 15000; let gActiveUpdate; +let gTimeoutRuns = 0; // Override getUpdatesRootDir on Mac because we need to apply the update // inside the bundle directory. @@ -300,7 +304,10 @@ function getUpdateTestDir() { 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(CHECK_TIMEOUT_MILLI, checkUpdateApplied); return; } diff --git 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 index 97e0a1c6aaa..a8d2735b805 100644 --- 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 @@ -27,6 +27,9 @@ 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 = 15000; @@ -36,6 +39,7 @@ Components.utils.import("resource://gre/modules/ctypes.jsm"); let gAppTimer; let gProcess; let gActiveUpdate; +let gTimeoutRuns = 0; // Override getUpdatesRootDir on Mac because we need to apply the update // inside the bundle directory. @@ -364,9 +368,13 @@ function getUpdateTestDir() { * Checks if the update has finished being applied in the background. */ function checkUpdateApplied() { + gTimeoutRuns++; // Don't proceed until the update has been applied. if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for update to be applied to the platform"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); return; } @@ -381,7 +389,10 @@ function checkUpdateApplied() { let log = getUpdatesDir(); log.append(FILE_LAST_LOG); if (!log.exists()) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); + 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); return; } @@ -468,11 +479,15 @@ function checkUpdateApplied() { * the test. */ function checkUpdateFinished() { + gTimeoutRuns++; // Don't proceed until the update status is no longer applied. try { let status = readStatusFile(); if (status != STATE_SUCCEEDED) { - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) + do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for success status"); + else + do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); return; } } catch (e) { @@ -484,9 +499,12 @@ function checkUpdateFinished() { 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. - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); + 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); return; } else { do_throw("getAppConsoleLogPath threw: " + e);