From 8f5f107a0541a1d11adf2793e131771e2bcc269d Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 28 Oct 2024 16:14:04 +0100 Subject: [PATCH] Rewrite searchcore job tracked maintenance job unit test to gtest. --- .../tests/proton/documentdb/CMakeLists.txt | 2 +- .../job_tracked_maintenance_job_test.cpp | 58 +++++++++++-------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/searchcore/src/tests/proton/documentdb/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/CMakeLists.txt index 4bb35ca86884..07662dbb5176 100644 --- a/searchcore/src/tests/proton/documentdb/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/CMakeLists.txt @@ -26,7 +26,6 @@ vespa_add_test(NAME searchcore_documentdb_test_app COMMAND searchcore_documentdb vespa_add_executable(searchcore_proton_documentdb_vespatest_test_app TEST SOURCES vespatest_runner.cpp - job_tracked_maintenance_job_test.cpp maintenancecontroller_test.cpp storeonlyfeedview_test.cpp DEPENDS @@ -52,6 +51,7 @@ vespa_add_executable(searchcore_proton_documentdb_gtest_test_app TEST documentmover_test.cpp executor_threading_service_test.cpp feedview_test.cpp + job_tracked_maintenance_job_test.cpp lid_space_common.cpp lid_space_compaction_test.cpp lid_space_handler_test.cpp diff --git a/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job_test.cpp b/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job_test.cpp index 7002a9c9ccfc..023976c0eee7 100644 --- a/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job_test.cpp +++ b/searchcore/src/tests/proton/documentdb/job_tracked_maintenance_job_test.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -61,24 +61,16 @@ struct Fixture GateVector _runGates; size_t _runIdx; ThreadStackExecutor _exec; - Fixture(size_t numRuns = 1) - : _tracker(std::make_shared(1)), - _job(std::make_unique(numRuns)), - _myJob(static_cast(_job.get())), - _trackedJob(std::make_unique(_tracker, std::move(_job))), - _runRetval(false), - _runGates(getGateVector(numRuns)), - _runIdx(0), - _exec(1) - { - } + + Fixture(size_t numRuns = 1); + ~Fixture(); void runJob() { _runRetval = _trackedJob->run(); _runGates[_runIdx++]->countDown(); } void assertTracker(size_t startedGateCount, size_t endedGateCount) { - EXPECT_EQUAL(startedGateCount, _tracker->_started.getCount()); - EXPECT_EQUAL(endedGateCount, _tracker->_ended.getCount()); + EXPECT_EQ(startedGateCount, _tracker->_started.getCount()); + EXPECT_EQ(endedGateCount, _tracker->_ended.getCount()); } void runJobAndWait(size_t runIdx, size_t startedGateCount, size_t endedGateCount) { _exec.execute(vespalib::makeLambdaTask([this]() { runJob(); })); @@ -89,23 +81,40 @@ struct Fixture } }; -TEST_F("require that maintenance job name, delay and interval are preserved", Fixture) +Fixture::Fixture(size_t numRuns) + : _tracker(std::make_shared(1)), + _job(std::make_unique(numRuns)), + _myJob(static_cast(_job.get())), + _trackedJob(std::make_unique(_tracker, std::move(_job))), + _runRetval(false), + _runGates(getGateVector(numRuns)), + _runIdx(0), + _exec(1) +{ +} + +Fixture::~Fixture() = default; + +TEST(JobTrackedMaintenanceJobTest, require_that_maintenance_job_name_delay_and_interval_are_preserved) { - EXPECT_EQUAL("myjob", f._trackedJob->getName()); - EXPECT_EQUAL(10s, f._trackedJob->getDelay()); - EXPECT_EQUAL(20s, f._trackedJob->getInterval()); + Fixture f; + EXPECT_EQ("myjob", f._trackedJob->getName()); + EXPECT_EQ(10s, f._trackedJob->getDelay()); + EXPECT_EQ(20s, f._trackedJob->getInterval()); } -TEST_F("require that maintenance job that needs 1 run is tracked", Fixture) +TEST(JobTrackedMaintenanceJobTest, require_that_maintenance_job_that_needs_1_run_is_tracked) { + Fixture f; f.assertTracker(1, 1); f.runJobAndWait(0, 0, 1); f.assertTracker(0, 0); EXPECT_TRUE(f._runRetval); } -TEST_F("require that maintenance job that needs several runs is tracked", Fixture(2)) +TEST(JobTrackedMaintenanceJobTest, require_that_maintenance_job_that_needs_several_runs_is_tracked) { + Fixture f(2); f.assertTracker(1, 1); f.runJobAndWait(0, 0, 1); f.assertTracker(0, 1); @@ -116,8 +125,9 @@ TEST_F("require that maintenance job that needs several runs is tracked", Fixtur EXPECT_TRUE(f._runRetval); } -TEST_F("require that maintenance job that is destroyed is tracked", Fixture(2)) +TEST(JobTrackedMaintenanceJobTest, require_that_maintenance_job_that_is_destroyed_is_tracked) { + Fixture f(2); f.assertTracker(1, 1); f.runJobAndWait(0, 0, 1); f.assertTracker(0, 1); @@ -127,8 +137,9 @@ TEST_F("require that maintenance job that is destroyed is tracked", Fixture(2)) f.assertTracker(0, 0); } -TEST_F("require that block calls are sent to underlying jobs", Fixture) +TEST(JobTrackedMaintenanceJobTest, require_that_block_calls_are_sent_to_underlying_jobs) { + Fixture f; EXPECT_FALSE(f._trackedJob->isBlocked()); EXPECT_TRUE(f._trackedJob->asBlockable() != nullptr); f._myJob->block(); @@ -139,8 +150,9 @@ TEST_F("require that block calls are sent to underlying jobs", Fixture) EXPECT_FALSE(f._trackedJob->isBlocked()); } -TEST_F("require that stop calls are sent to underlying jobs", Fixture) +TEST(JobTrackedMaintenanceJobTest, require_that_stop_calls_are_sent_to_underlying_jobs) { + Fixture f; EXPECT_FALSE(f._myJob->stopped()); f._trackedJob->stop(); EXPECT_TRUE(f._myJob->stopped());