Bug 1529043 - Part 4 (test only) - Make the waitForHelperExit function async and change call sites so they use await. r=mhowell

Depends on D20795

Differential Revision: https://phabricator.services.mozilla.com/D20796

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Robert Strong 2019-02-22 21:05:02 +00:00
parent 243cdb26c0
commit b406776b49
31 changed files with 81 additions and 271 deletions

View File

@ -2633,55 +2633,45 @@ async function waitForHelperSleep() {
}, "Waiting for file to be removed, Path: " + file.path);
}
/**
* Helper function that waits until the helper has finished its operations
* before calling waitForHelperFinishFileUnlock to verify that the helper's
* input and output directories are no longer in use.
*/
function waitForHelperFinished() {
// Give the lock file process time to lock the file before updating otherwise
// this test can fail intermittently on Windows debug builds.
let output = getApplyDirFile(DIR_RESOURCES + "output");
if (readFile(output) != "finished\n") {
// Uses do_timeout instead of do_execute_soon to lessen log spew.
do_timeout(FILE_IN_USE_TIMEOUT_MS, waitForHelperFinished);
return;
}
// Give the lock file process time to unlock the file before deleting the
// input and output files.
waitForHelperFinishFileUnlock();
}
/**
* Helper function that waits until the helper's input and output files are no
* longer in use before calling waitForHelperExitFinished.
*/
function waitForHelperFinishFileUnlock() {
try {
let output = getApplyDirFile(DIR_RESOURCES + "output");
if (output.exists()) {
output.remove(false);
}
let input = getApplyDirFile(DIR_RESOURCES + "input");
if (input.exists()) {
input.remove(false);
}
} catch (e) {
// Give the lock file process time to unlock the file before deleting the
// input and output files.
executeSoon(waitForHelperFinishFileUnlock);
return;
}
executeSoon(waitForHelperExitFinished);
}
/**
* Helper function to tell the helper to finish and exit its sleep state.
*/
function waitForHelperExit() {
let input = getApplyDirFile(DIR_RESOURCES + "input");
writeFile(input, "finish\n");
waitForHelperFinished();
async function waitForHelperExit() {
let file = getApplyDirFile(DIR_RESOURCES + "input");
writeFile(file, "finish\n");
// Give the lock file process time to lock the file before updating otherwise
// this test can fail intermittently on Windows debug builds.
file = getApplyDirFile(DIR_RESOURCES + "output");
await TestUtils.waitForCondition(() => (file.exists()),
"Waiting for file to exist, Path: " + file.path);
let expectedContents = "finished\n";
await TestUtils.waitForCondition(() => (readFile(file) == expectedContents),
"Waiting for expected file contents: " + expectedContents);
// Give the lock file process time to unlock the file before deleting the
// input and output files.
await TestUtils.waitForCondition(() => {
try {
file.remove(false);
} catch (e) {
debugDump("failed to remove file. Path: " + file.path +
", Exception: " + e);
}
return !file.exists();
}, "Waiting for file to be removed, Path: " + file.path);
file = getApplyDirFile(DIR_RESOURCES + "input");
await TestUtils.waitForCondition(() => {
try {
file.remove(false);
} catch (e) {
debugDump("failed to remove file. Path: " + file.path +
", Exception: " + e);
}
return !file.exists();
}, "Waiting for file to be removed, Path: " + file.path);
}
/**

View File

@ -27,19 +27,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -31,19 +31,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_SUCCEEDED, true, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -19,13 +19,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestFiles[13].relPathDir + gTestFiles[13].fileName,
false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestFiles[11].relPathDir + gTestFiles[11].fileName,
false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -20,13 +20,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperLockFile(gTestFiles[3]);
runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -20,13 +20,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperLockFile(gTestFiles[2]);
runUpdate(STATE_FAILED_READ_ERROR, false, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -27,20 +27,14 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
// Files aren't checked after staging since this test locks a file which
// prevents reading the file.
checkUpdateLogContains(ERR_ENSURE_COPY);
// Switch the application to the staged application that was updated.
runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, false);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -27,20 +27,14 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
// Files aren't checked after staging since this test locks a file which
// prevents reading the file.
checkUpdateLogContains(ERR_ENSURE_COPY);
// Switch the application to the staged application that was updated.
runUpdate(STATE_FAILED_READ_ERROR, false, 1, false);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -19,13 +19,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperPIDPersists(DIR_RESOURCES + gCallbackBinFile, false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -29,19 +29,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestDirs[4].relPathDir + gTestDirs[4].subDirs[0] +
gTestDirs[4].subDirFiles[0], true);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -19,13 +19,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestDirs[2].relPathDir + gTestDirs[2].files[0], true);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -27,19 +27,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -19,13 +19,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperFileInUse(DIR_RESOURCES + gCallbackBinFile, false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestFiles[13].relPathDir + gTestFiles[13].fileName,
false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestFiles[11].relPathDir + gTestFiles[11].fileName,
false);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -20,13 +20,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperLockFile(gTestFiles[3]);
runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -20,13 +20,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperLockFile(gTestFiles[2]);
runUpdate(STATE_FAILED_READ_ERROR, false, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -27,20 +27,14 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
// Files aren't checked after staging since this test locks a file which
// prevents reading the file.
checkUpdateLogContains(ERR_ENSURE_COPY);
// Switch the application to the staged application that was updated.
runUpdate(STATE_FAILED_WRITE_ERROR, false, 1, false);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -27,20 +27,14 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
// Files aren't checked after staging since this test locks a file which
// prevents reading the file.
checkUpdateLogContains(ERR_ENSURE_COPY);
// Switch the application to the staged application that was updated.
runUpdate(STATE_FAILED_READ_ERROR, false, 1, false);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateFailure(getApplyDirFile);

View File

@ -29,19 +29,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_COMPLETE_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -28,19 +28,13 @@ async function setupUpdaterTestFinished() {
/**
* Called after the call to stageUpdate finishes.
*/
function stageUpdateFinished() {
async function stageUpdateFinished() {
checkPostUpdateRunningFile(false);
checkFilesAfterUpdateSuccess(getStageDirFile, true);
checkUpdateLogContents(LOG_PARTIAL_SUCCESS, true);
// Switch the application to the staged application that was updated.
runUpdate(STATE_AFTER_RUNUPDATE, true, 1, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
async function waitForHelperExitFinished() {
await waitForHelperExit();
standardInit();
checkPostUpdateRunningFile(false);
setTestFilesAndDirsForFailure();

View File

@ -20,13 +20,7 @@ async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestDirs[4].relPathDir + gTestDirs[4].subDirs[0] +
gTestDirs[4].subDirFiles[0], true);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}

View File

@ -19,13 +19,7 @@ function run_test() {
async function setupUpdaterTestFinished() {
await runHelperFileInUse(gTestDirs[2].relPathDir + gTestDirs[2].files[0], true);
runUpdate(STATE_SUCCEEDED, false, 0, true);
waitForHelperExit();
}
/**
* Called after the call to waitForHelperExit finishes.
*/
function waitForHelperExitFinished() {
await waitForHelperExit();
checkPostUpdateAppLog();
}