From 392d2ea39da99af49c3d512262cb27f22ab1311f Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 19 Nov 2019 18:10:04 +0900 Subject: [PATCH] Fix smoke-test functions for rollback cases The custom step cannot be added outside of installer, because steps are initialized when Run() invoked. (If some step added outside of installer, that step will be executed at first, ignoring original steps) This patch defines a new virtual function creating overridden installer object which is fail at the end of steps or specific stage. Change-Id: I00eed98d51bb4d083c421baa6a83f4b8ca17e90d Signed-off-by: Sangyoon Jang --- src/unit_tests/common/smoke_utils.cc | 9 +++++---- src/unit_tests/common/smoke_utils.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/unit_tests/common/smoke_utils.cc b/src/unit_tests/common/smoke_utils.cc index 8f62dd9..e7abce1 100644 --- a/src/unit_tests/common/smoke_utils.cc +++ b/src/unit_tests/common/smoke_utils.cc @@ -511,10 +511,10 @@ void BackendInterface::TestRollbackAfterEachStep(int argc, const char* argv[], LOG(ERROR) << "Failed to initialize pkgmgr interface"; return; } - auto backend = CreateInstaller(pkgmgr); + AppInstallerPtr backend; int i; for (i = backend->StepCount() - 1; i >= 0; i--) { - backend->AddStepAtIndex(i); + backend = CreateFailExpectedInstaller(pkgmgr, i); LOG(DEBUG) << "StepFail is inserted at: " << i; ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend->Run()); if (!validator()) @@ -560,12 +560,13 @@ void BackendInterface::CrashAfterEachStep(std::vector* args, BackendInterface::CommandResult BackendInterface::RunInstallerWithPkgrmgr( ci::PkgMgrPtr pkgmgr) const { - std::unique_ptr installer = CreateInstaller(pkgmgr); + std::unique_ptr installer; switch (mode_) { case RequestResult::FAIL: - installer->AddStep(); + installer = CreateFailExpectedInstaller(pkgmgr); break; default: + installer = CreateInstaller(pkgmgr); break; } return installer->Run(); diff --git a/src/unit_tests/common/smoke_utils.h b/src/unit_tests/common/smoke_utils.h index d65d4a0..41ba53b 100644 --- a/src/unit_tests/common/smoke_utils.h +++ b/src/unit_tests/common/smoke_utils.h @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -275,6 +274,8 @@ class BackendInterface { virtual AppQueryInterfacePtr CreateQueryInterface() const = 0; virtual AppInstallerPtr CreateInstaller( common_installer::PkgMgrPtr pkgmgr) const = 0; + virtual AppInstallerPtr CreateFailExpectedInstaller( + common_installer::PkgMgrPtr pkgmgr, int fail_at = -1) const = 0; }; bool CheckAvailableExternalPath(); -- 2.7.4