Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryfu-msft committed Nov 10, 2023
1 parent a02b23c commit 5a16c00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ namespace AppInstaller::CLI::Execution
{
if (Settings::ExperimentalFeature::IsEnabled(ExperimentalFeature::Feature::Resume))
{
if (m_checkpointManager && IsTerminated() && GetTerminationHR() != APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_INSTALL)
if (m_checkpointManager && (!IsTerminated() || GetTerminationHR() != APPINSTALLER_CLI_ERROR_INSTALL_REBOOT_REQUIRED_TO_INSTALL))
{
m_checkpointManager->CleanUpDatabase();
}
Expand Down
57 changes: 15 additions & 42 deletions src/AppInstallerCLITests/ResumeFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,62 +256,35 @@ TEST_CASE("ResumeFlow_ResumeLimitExceeded", "[Resume]")
return;
}

TestCommon::TempDirectory tempCheckpointRecordDirectory("TempCheckpointRecordDirectory", false);
TestCommon::TempDirectory tempCheckpointsLocationDir("TempCheckpointsLocationDir", true);

const auto& tempCheckpointRecordDirectoryPath = tempCheckpointRecordDirectory.GetPath();
const auto& tempCheckpointRecordDirectoryPath = tempCheckpointsLocationDir.GetPath();
TestHook_SetPathOverride(PathName::CheckpointsLocation, tempCheckpointRecordDirectoryPath);

TestCommon::TestUserSettings testSettings;
testSettings.Set<Setting::EFResume>(true);
testSettings.Set<Setting::EFReboot>(true);
testSettings.Set<Setting::EFWindowsFeature>(true);
testSettings.Set<Setting::MaxResumes>(1);

std::ostringstream installOutput;
TestContext context{ installOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();

// Override with reboot required HRESULT.
auto doesFeatureExistOverride = TestHook::SetDoesWindowsFeatureExistResult_Override(ERROR_SUCCESS);
auto setEnableFeatureOverride = TestHook::SetEnableWindowsFeatureResult_Override(ERROR_SUCCESS_REBOOT_REQUIRED);

TestHook::SetRegisterForRestartResult_Override registerForRestartResultOverride(true);
TestHook::SetInitiateRebootResult_Override initiateRebootResultOverride(true);

const auto& testManifestPath = TestDataFile("InstallFlowTest_WindowsFeatures.yaml").GetPath().u8string();
context.Args.AddArg(Execution::Args::Type::Manifest, testManifestPath);
context.Args.AddArg(Execution::Args::Type::AllowReboot);
context.Args.AddArg(Execution::Args::Type::AcceptSourceAgreements);

InstallCommand install({});
context.SetExecutingCommand(&install);
install.Execute(context);
INFO(installOutput.str());

std::string resumeId;
for (const auto& entry : std::filesystem::directory_iterator(tempCheckpointRecordDirectoryPath))
{
// There should only be one checkpoint folder created.
resumeId = entry.path().filename().u8string();
}
std::filesystem::path testResumeId = L"testResumeId";
std::filesystem::path tempResumeDir = tempCheckpointRecordDirectoryPath / testResumeId;
std::filesystem::path tempCheckpointDatabasePath = tempResumeDir / L"checkpoints.db";

{
// Execute resume once.
std::ostringstream resumeOutput;
TestContext resumeContext{ resumeOutput, std::cin };
previousThreadGlobals = resumeContext.SetForCurrentThread();
resumeContext.Args.AddArg(Execution::Args::Type::ResumeId, resumeId);

ResumeCommand resume({});
resume.Execute(resumeContext);
std::filesystem::create_directory(tempResumeDir);
std::shared_ptr<CheckpointDatabase> database = CheckpointDatabase::CreateNew(tempCheckpointDatabasePath.u8string(), {1, 0});
std::string_view testCheckpointName = "testCheckpoint"sv;

CheckpointDatabase::IdType checkpointId = database->AddCheckpoint(testCheckpointName);
database->SetDataValue(checkpointId, AutomaticCheckpointData::Command, {}, { "install" });
database->SetDataValue(checkpointId, AutomaticCheckpointData::ClientVersion, {}, { GetClientVersion()});
database->SetDataValue(checkpointId, AutomaticCheckpointData::ResumeCount, {}, {"1"});
}

{
// Resume should fail as the resume limit has been exceeded.
std::ostringstream resumeOutput;
TestContext resumeContext{ resumeOutput, std::cin };
previousThreadGlobals = resumeContext.SetForCurrentThread();
resumeContext.Args.AddArg(Execution::Args::Type::ResumeId, resumeId);
auto previousThreadGlobals = resumeContext.SetForCurrentThread();
resumeContext.Args.AddArg(Execution::Args::Type::ResumeId, testResumeId.u8string());

ResumeCommand resume({});
resume.Execute(resumeContext);
Expand Down

0 comments on commit 5a16c00

Please sign in to comment.