From e20b2bd8331ea2de0be3670e34380c88c5162129 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 3 Jun 2015 11:29:51 -0700 Subject: [PATCH] Bug 1165061 - Fix Intermittent test_0102_background_restartNotification_staging.xul by not copying app files when staging for tests and enable the tests for Linux and Mac. r=spohl --- .../mozapps/update/tests/chrome/chrome.ini | 12 +- .../chrome/test_0017_check_staging_basic.xul | 2 + ...6_restartNotification_stagedBackground.xul | 2 + ...rtNotification_stagedServiceBackground.xul | 2 + ...background_restartNotification_staging.xul | 2 + ...und_restartNotification_stagingService.xul | 2 + .../update/tests/chrome/test_9999_cleanup.xul | 24 ++- toolkit/mozapps/update/tests/chrome/utils.js | 164 +++++++++++++----- toolkit/mozapps/update/tests/data/shared.js | 4 + .../mozapps/update/updater/archivereader.cpp | 4 +- .../update/updater/updater-xpcshell/moz.build | 2 +- toolkit/mozapps/update/updater/updater.cpp | 11 ++ toolkit/mozapps/update/updater/updater.rc | 2 +- 13 files changed, 180 insertions(+), 53 deletions(-) diff --git a/toolkit/mozapps/update/tests/chrome/chrome.ini b/toolkit/mozapps/update/tests/chrome/chrome.ini index eb74447567fc..2903c0d4901d 100644 --- a/toolkit/mozapps/update/tests/chrome/chrome.ini +++ b/toolkit/mozapps/update/tests/chrome/chrome.ini @@ -18,8 +18,8 @@ support-files = [test_0015_check_incompat_basic_addons.xul] [test_0016_check_incompat_basic_license_addons.xul] [test_0017_check_staging_basic.xul] -skip-if = os != 'win' -reason = Bug 918029 and bug 1164560 - timeout caused by copying too many files. +skip-if = asan +reason = Bug 1168003 [test_0021_check_billboard.xul] [test_0022_check_billboard_license.xul] [test_0023_check_incompat_billboard.xul] @@ -60,11 +60,15 @@ reason = Bug 918029 and bug 1164560 - timeout caused by copying too many files. [test_0094_restartNotification_remote.xul] [test_0095_restartNotification_remoteInvalidNumber.xul] [test_0096_restartNotification_stagedBackground.xul] +skip-if = asan +reason = Bug 1168003 [test_0097_restartNotification_stagedServiceBackground.xul] +skip-if = os != 'win' +reason = only Windows has the maintenance service. [test_0101_background_restartNotification.xul] [test_0102_background_restartNotification_staging.xul] -skip-if = os == 'linux' -reason = Bug 918029 - timeout caused by copying too many files. +skip-if = asan +reason = Bug 1168003 [test_0103_background_restartNotification_stagingService.xul] skip-if = os != 'win' reason = only Windows has the maintenance service. diff --git a/toolkit/mozapps/update/tests/chrome/test_0017_check_staging_basic.xul b/toolkit/mozapps/update/tests/chrome/test_0017_check_staging_basic.xul index ab08cb83f225..a20966a28e59 100644 --- a/toolkit/mozapps/update/tests/chrome/test_0017_check_staging_basic.xul +++ b/toolkit/mozapps/update/tests/chrome/test_0017_check_staging_basic.xul @@ -31,6 +31,8 @@ const TESTS = [ { buttonClick: "extra1" } ]; +gUseTestUpdater = true; + function runTest() { debugDump("entering"); diff --git a/toolkit/mozapps/update/tests/chrome/test_0096_restartNotification_stagedBackground.xul b/toolkit/mozapps/update/tests/chrome/test_0096_restartNotification_stagedBackground.xul index ba43af8c4cee..b86861012c9c 100644 --- a/toolkit/mozapps/update/tests/chrome/test_0096_restartNotification_stagedBackground.xul +++ b/toolkit/mozapps/update/tests/chrome/test_0096_restartNotification_stagedBackground.xul @@ -24,6 +24,8 @@ const TESTS = [ { buttonClick: "extra1" } ]; +gUseTestUpdater = true; + function runTest() { debugDump("entering"); diff --git a/toolkit/mozapps/update/tests/chrome/test_0097_restartNotification_stagedServiceBackground.xul b/toolkit/mozapps/update/tests/chrome/test_0097_restartNotification_stagedServiceBackground.xul index 852a16f2bae3..9f7a602c4f12 100644 --- a/toolkit/mozapps/update/tests/chrome/test_0097_restartNotification_stagedServiceBackground.xul +++ b/toolkit/mozapps/update/tests/chrome/test_0097_restartNotification_stagedServiceBackground.xul @@ -24,6 +24,8 @@ const TESTS = [ { buttonClick: "extra1" } ]; +gUseTestUpdater = true; + function runTest() { debugDump("entering"); diff --git a/toolkit/mozapps/update/tests/chrome/test_0102_background_restartNotification_staging.xul b/toolkit/mozapps/update/tests/chrome/test_0102_background_restartNotification_staging.xul index 25e96a7e2811..7491d3f61f9b 100644 --- a/toolkit/mozapps/update/tests/chrome/test_0102_background_restartNotification_staging.xul +++ b/toolkit/mozapps/update/tests/chrome/test_0102_background_restartNotification_staging.xul @@ -24,6 +24,8 @@ const TESTS = [ { buttonClick: "extra1" } ]; +gUseTestUpdater = true; + function runTest() { debugDump("entering"); diff --git a/toolkit/mozapps/update/tests/chrome/test_0103_background_restartNotification_stagingService.xul b/toolkit/mozapps/update/tests/chrome/test_0103_background_restartNotification_stagingService.xul index fb04ea069d27..c007b8134880 100644 --- a/toolkit/mozapps/update/tests/chrome/test_0103_background_restartNotification_stagingService.xul +++ b/toolkit/mozapps/update/tests/chrome/test_0103_background_restartNotification_stagingService.xul @@ -24,6 +24,8 @@ const TESTS = [ { buttonClick: "extra1" } ]; +gUseTestUpdater = true; + function runTest() { debugDump("entering"); diff --git a/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul b/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul index 2c5fd349454b..54792b02b761 100644 --- a/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul +++ b/toolkit/mozapps/update/tests/chrome/test_9999_cleanup.xul @@ -81,7 +81,29 @@ function runTest() { ", Exception: " + e); } - resetAddons(finishTest); + resetAddons(cleanupRestoreUpdaterBackup); +} + +/** + * After all tests finish this will repeatedly attempt to restore the real + * updater if it exists and then call finishTest after the restore is + * successful. + */ +function cleanupRestoreUpdaterBackup() { + debugDump("entering"); + + try { + // Windows debug builds keep the updater file in use for a short period of + // time after the updater process exits. + restoreUpdaterBackup(); + } catch (e) { + logTestInfo("Attempt to restore the backed up updater failed... " + + "will try again, Exception: " + e); + SimpleTest.executeSoon(cleanupRestoreUpdaterBackup); + return; + } + + SimpleTest.executeSoon(finishTest); } function finishTest() { diff --git a/toolkit/mozapps/update/tests/chrome/utils.js b/toolkit/mozapps/update/tests/chrome/utils.js index 979e1a926cc5..83d335a6ada7 100644 --- a/toolkit/mozapps/update/tests/chrome/utils.js +++ b/toolkit/mozapps/update/tests/chrome/utils.js @@ -216,6 +216,7 @@ var gPrefToCheck; var gDisableNoUpdateAddon = false; var gDisableUpdateCompatibilityAddon = false; var gDisableUpdateVersionAddon = false; +var gUseTestUpdater = false; // Set to true to log additional information for debugging. To log additional // information for an individual test set DEBUG_AUS_TEST to true in the test's @@ -330,9 +331,10 @@ function runTestDefaultWaitForWindowClosed() { setupFiles(); setupPrefs(); + gEnv.set("MOZ_TEST_SKIP_UPDATE_STAGE", "1"); removeUpdateDirsAndFiles(); reloadUpdateManagerData(); - setupAddons(runTest); + setupAddons(setupTestUpdater); } } @@ -358,6 +360,7 @@ function finishTestDefault() { verifyTestsRan(); resetPrefs(); + gEnv.set("MOZ_TEST_SKIP_UPDATE_STAGE", ""); resetFiles(); removeUpdateDirsAndFiles(); reloadUpdateManagerData(); @@ -367,7 +370,7 @@ function finishTestDefault() { gDocElem.removeEventListener("pageshow", onPageShowDefault, false); } - finishTestDefaultWaitForWindowClosed(); + finishTestRestoreUpdaterBackup(); } /** @@ -390,6 +393,28 @@ function finishTestTimeout(aTimer) { } } +/** + * When a test finishes this will repeatedly attempt to restore the real updater + * for tests that use the test updater and then call + * finishTestDefaultWaitForWindowClosed after the restore is successful. + */ +function finishTestRestoreUpdaterBackup() { + if (gUseTestUpdater) { + try { + // Windows debug builds keep the updater file in use for a short period of + // time after the updater process exits. + restoreUpdaterBackup(); + } catch (e) { + logTestInfo("Attempt to restore the backed up updater failed... " + + "will try again, Exception: " + e); + SimpleTest.executeSoon(finishTestRestoreUpdaterBackup); + return; + } + } + + finishTestDefaultWaitForWindowClosed(); +} + /** * If an update window is found SimpleTest.executeSoon can callback before the * update window is fully closed especially with debug builds. If an update @@ -400,6 +425,7 @@ function finishTestTimeout(aTimer) { function finishTestDefaultWaitForWindowClosed() { gCloseWindowTimeoutCounter++; if (gCloseWindowTimeoutCounter > CLOSE_WINDOW_TIMEOUT_MAXCOUNT) { + SimpleTest.requestCompleteLog(); SimpleTest.finish(); return; } @@ -752,7 +778,7 @@ function checkIncompatbleList() { for (let i = 0; i < gIncompatibleListbox.itemCount; i++) { let label = gIncompatibleListbox.getItemAtIndex(i).label; // Use indexOf since locales can change the text displayed - ok(label.indexOf("noupdate") != -1, "Checking that only incompatible " + + ok(label.indexOf("noupdate") != -1, "Checking that only incompatible " + "add-ons that don't have an update are listed in the incompatible list"); } } @@ -875,26 +901,6 @@ function verifyTestsRan() { } } -/** - * Restore the updater that was backed up. This is called both in setupFiles - * and resetFiles. It is called in setupFiles before the backup is done in - * case the previous test failed. It is called in resetFiles to put things - * back to its original state. - */ -function resetUpdaterBackup() { - let baseAppDir = getAppBaseDir(); - let updater = baseAppDir.clone(); - let updaterBackup = baseAppDir.clone(); - updater.append(FILE_UPDATER_BIN); - updaterBackup.append(FILE_UPDATER_BIN_BAK); - if (updaterBackup.exists()) { - if (updater.exists()) { - updater.remove(true); - } - updaterBackup.moveTo(baseAppDir, FILE_UPDATER_BIN); - } -} - /** * Creates a backup of files the tests need to modify so they can be restored to * the original file when the test has finished and then modifies the files. @@ -910,30 +916,101 @@ function setupFiles() { updateSettingsIni = baseAppDir.clone(); updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS); +} - // Just in case the last test failed, try to reset. - resetUpdaterBackup(); - - // Move away the real updater - let updater = baseAppDir.clone(); - updater.append(FILE_UPDATER_BIN); - updater.moveTo(baseAppDir, FILE_UPDATER_BIN_BAK); - - // Move in the test only updater - let testUpdaterDir = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties). - get("CurWorkD", Ci.nsILocalFile); - - let relPath = REL_PATH_DATA; - let pathParts = relPath.split("/"); - for (let i = 0; i < pathParts.length; ++i) { - testUpdaterDir.append(pathParts[i]); +/** + * For tests that use the test updater restores the backed up real updater if + * it exists and tries again on failure since Windows debug builds at times + * leave the file in use. After success moveRealUpdater is called to continue + * the setup of the test updater. For tests that don't use the test updater + * runTest will be called. + */ +function setupTestUpdater() { + if (!gUseTestUpdater) { + runTest(); + return; } - let testUpdater = testUpdaterDir.clone(); - testUpdater.append(FILE_UPDATER_BIN); - if (testUpdater.exists()) { + try { + restoreUpdaterBackup(); + } catch (e) { + logTestInfo("Attempt to restore the backed up updater failed... " + + "will try again, Exception: " + e); + SimpleTest.executeSoon(setupTestUpdater); + return; + } + moveRealUpdater(); +} + +/** + * Backs up the real updater and tries again on failure since Windows debug + * builds at times leave the file in use. After success it will call + * copyTestUpdater to continue the setup of the test updater. + */ +function moveRealUpdater() { + try { + // Move away the real updater + let baseAppDir = getAppBaseDir(); + let updater = baseAppDir.clone(); + updater.append(FILE_UPDATER_BIN); + updater.moveTo(baseAppDir, FILE_UPDATER_BIN_BAK); + } catch (e) { + logTestInfo("Attempt to move the real updater out of the way failed... " + + "will try again, Exception: " + e); + SimpleTest.executeSoon(moveRealUpdater); + return; + } + + copyTestUpdater(); +} + +/** + * Copies the test updater so it can be used by tests and tries again on failure + * since Windows debug builds at times leave the file in use. After success it + * will call runTest to continue the test. + */ +function copyTestUpdater() { + try { + // Copy the test updater + let baseAppDir = getAppBaseDir(); + let testUpdaterDir = Services.dirsvc.get("CurWorkD", Ci.nsILocalFile); + let relPath = REL_PATH_DATA; + let pathParts = relPath.split("/"); + for (let i = 0; i < pathParts.length; ++i) { + testUpdaterDir.append(pathParts[i]); + } + + let testUpdater = testUpdaterDir.clone(); + testUpdater.append(FILE_UPDATER_BIN); testUpdater.copyToFollowingLinks(baseAppDir, FILE_UPDATER_BIN); + } catch (e) { + logTestInfo("Attempt to copy the test updater failed... " + + "will try again, Exception: " + e); + SimpleTest.executeSoon(copyTestUpdater); + return; + } + + runTest(); +} + +/** + * Restores the updater that was backed up. This is called in setupTestUpdater + * before the backup of the real updater is done in case the previous test + * failed to restore the updater, in finishTestDefaultWaitForWindowClosed when + * the test has finished, and in test_9999_cleanup.xul after all tests have + * finished. + */ +function restoreUpdaterBackup() { + let baseAppDir = getAppBaseDir(); + let updater = baseAppDir.clone(); + let updaterBackup = baseAppDir.clone(); + updater.append(FILE_UPDATER_BIN); + updaterBackup.append(FILE_UPDATER_BIN_BAK); + if (updaterBackup.exists()) { + if (updater.exists()) { + updater.remove(true); + } + updaterBackup.moveTo(baseAppDir, FILE_UPDATER_BIN); } } @@ -1022,7 +1099,6 @@ function resetFiles() { ", Exception: " + e); } } - resetUpdaterBackup(); } /** diff --git a/toolkit/mozapps/update/tests/data/shared.js b/toolkit/mozapps/update/tests/data/shared.js index dd5fd4365f96..d6ea47a7a1b7 100644 --- a/toolkit/mozapps/update/tests/data/shared.js +++ b/toolkit/mozapps/update/tests/data/shared.js @@ -130,6 +130,10 @@ XPCOMUtils.defineLazyGetter(this, "gPrefRoot", function test_gPR() { return Services.prefs.getBranch(null); }); +XPCOMUtils.defineLazyServiceGetter(this, "gEnv", + "@mozilla.org/process/environment;1", + "nsIEnvironment"); + XPCOMUtils.defineLazyGetter(this, "gZipW", function test_gZipW() { return Cc["@mozilla.org/zipwriter;1"]. createInstance(Ci.nsIZipWriter); diff --git a/toolkit/mozapps/update/updater/archivereader.cpp b/toolkit/mozapps/update/updater/archivereader.cpp index fe10327d4eb5..90cf45c3dbd3 100644 --- a/toolkit/mozapps/update/updater/archivereader.cpp +++ b/toolkit/mozapps/update/updater/archivereader.cpp @@ -18,7 +18,7 @@ // These are generated at compile time based on the DER file for the channel // being used #ifdef MOZ_VERIFY_MAR_SIGNATURE -#ifdef UPDATER_XPCSHELL_CERT +#ifdef TEST_UPDATER #include "../xpcshellCert.h" #else #include "primaryCert.h" @@ -85,7 +85,7 @@ ArchiveReader::VerifySignature() #ifndef MOZ_VERIFY_MAR_SIGNATURE return OK; #else -#ifdef UPDATER_XPCSHELL_CERT +#ifdef TEST_UPDATER int rv = VerifyLoadedCert(mArchive, xpcshellCertData); #else int rv = VerifyLoadedCert(mArchive, primaryCertData); diff --git a/toolkit/mozapps/update/updater/updater-xpcshell/moz.build b/toolkit/mozapps/update/updater/updater-xpcshell/moz.build index eab7c708a41a..ba5c844cfc10 100644 --- a/toolkit/mozapps/update/updater/updater-xpcshell/moz.build +++ b/toolkit/mozapps/update/updater/updater-xpcshell/moz.build @@ -8,6 +8,6 @@ Program('updater-xpcshell') updater_rel_path = '../' DIST_INSTALL = False -DEFINES['UPDATER_XPCSHELL_CERT'] = True +DEFINES['TEST_UPDATER'] = True include('../updater-common.build') FAIL_ON_WARNINGS = True diff --git a/toolkit/mozapps/update/updater/updater.cpp b/toolkit/mozapps/update/updater/updater.cpp index 5120f7603ad4..8d7e9ee820de 100644 --- a/toolkit/mozapps/update/updater/updater.cpp +++ b/toolkit/mozapps/update/updater/updater.cpp @@ -2262,7 +2262,18 @@ UpdateThreadFunc(void *param) #endif if (rv == OK && sStagedUpdate && !sIsOSUpdate) { +#ifdef TEST_UPDATER + // The MOZ_TEST_SKIP_UPDATE_STAGE environment variable prevents copying + // the files in dist/bin in the test updater when staging an update since + // this can cause tests to timeout. + if (getenv("MOZ_TEST_SKIP_UPDATE_STAGE")) { + rv = OK; + } else { + rv = CopyInstallDirToDestDir(); + } +#else rv = CopyInstallDirToDestDir(); +#endif } if (rv == OK) { diff --git a/toolkit/mozapps/update/updater/updater.rc b/toolkit/mozapps/update/updater/updater.rc index 707efeafda79..7603eecb645a 100644 --- a/toolkit/mozapps/update/updater/updater.rc +++ b/toolkit/mozapps/update/updater/updater.rc @@ -4,7 +4,7 @@ // Microsoft Visual C++ generated resource script. // -#ifdef UPDATER_XPCSHELL_CERT +#ifdef TEST_UPDATER #include "../resource.h" #define MANIFEST_PATH "../updater.exe.manifest" #define COMCTL32_MANIFEST_PATH "../updater.exe.comctl32.manifest"