Skip to content

Commit

Permalink
Merge pull request #32694 from vespa-engine/toregge/rewrite-searchcor…
Browse files Browse the repository at this point in the history
…e-job-tracked-maintenance-job-unit-test-to-gtest

Rewrite searchcore job tracked maintenance job unit test to gtest.
  • Loading branch information
toregge authored Oct 28, 2024
2 parents 50ae33a + 8f5f107 commit 6647be5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion searchcore/src/tests/proton/documentdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <vespa/searchcore/proton/server/i_blockable_maintenance_job.h>
#include <vespa/searchcore/proton/server/job_tracked_maintenance_job.h>
#include <vespa/searchcore/proton/test/simple_job_tracker.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/vespalib/util/gate.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
Expand Down Expand Up @@ -61,24 +61,16 @@ struct Fixture
GateVector _runGates;
size_t _runIdx;
ThreadStackExecutor _exec;
Fixture(size_t numRuns = 1)
: _tracker(std::make_shared<SimpleJobTracker>(1)),
_job(std::make_unique<MyMaintenanceJob>(numRuns)),
_myJob(static_cast<MyMaintenanceJob *>(_job.get())),
_trackedJob(std::make_unique<JobTrackedMaintenanceJob>(_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(); }));
Expand All @@ -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<SimpleJobTracker>(1)),
_job(std::make_unique<MyMaintenanceJob>(numRuns)),
_myJob(static_cast<MyMaintenanceJob *>(_job.get())),
_trackedJob(std::make_unique<JobTrackedMaintenanceJob>(_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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
Expand Down

0 comments on commit 6647be5

Please sign in to comment.