summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-12-13 06:08:33 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-12-13 06:08:33 +0000
commit0292b25bf3be780df933be21a7a489dbf5658934 (patch)
treea3495ad292772d65e5adbcafead6ba4b71fd4fca /searchcore
parentc18edfbdb8a31befad1d7e6b0085fc2d435b8540 (diff)
Add unit test for proper sequencing of task execution and synchronous cleanup.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/common/timer/timer_test.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/common/timer/timer_test.cpp b/searchcore/src/tests/proton/common/timer/timer_test.cpp
index 0f517a00a5d..23180fc1aba 100644
--- a/searchcore/src/tests/proton/common/timer/timer_test.cpp
+++ b/searchcore/src/tests/proton/common/timer/timer_test.cpp
@@ -8,10 +8,12 @@
#include <vespa/vespalib/util/count_down_latch.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
+#include <vespa/vespalib/util/lambdatask.h>
using vespalib::Executor;
using namespace proton;
using Task = Executor::Task;
+using vespalib::makeLambdaTask;
namespace {
@@ -83,4 +85,32 @@ TYPED_TEST(ScheduledExecutorTest, test_drop_handle) {
EXPECT_TRUE(latch1.await(60s));
}
+TYPED_TEST(ScheduledExecutorTest, test_only_one_instance_running) {
+ vespalib::Gate latch;
+ std::atomic<uint64_t> counter = 0;
+ auto handleA = this->timer->scheduleAtFixedRate(makeLambdaTask([&]() { counter++; latch.await();}), 0ms, 1ms);
+ std::this_thread::sleep_for(2s);
+ EXPECT_EQ(1, counter);
+ latch.countDown();
+ std::this_thread::sleep_for(2s);
+ EXPECT_GT(counter, 10);
+}
+
+TYPED_TEST(ScheduledExecutorTest, test_sync_delete) {
+ vespalib::Gate latch;
+ std::atomic<uint64_t> counter = 0;
+ std::atomic<uint64_t> reset_counter = 0;
+ auto handleA = this->timer->scheduleAtFixedRate(makeLambdaTask([&]() { counter++; latch.await();}), 0ms, 1ms);
+ auto handleB = this->timer->scheduleAtFixedRate(makeLambdaTask([&]() { handleA.reset(); reset_counter++; }), 0ms, 1ms);
+ std::this_thread::sleep_for(2s);
+ EXPECT_EQ(1, counter);
+ EXPECT_EQ(0, reset_counter);
+ latch.countDown();
+ std::this_thread::sleep_for(2s);
+ EXPECT_EQ(1, counter);
+ EXPECT_GT(reset_counter, 10);
+ EXPECT_EQ(nullptr, handleA.get());
+ EXPECT_FALSE(nullptr == handleB.get());
+}
+
GTEST_MAIN_RUN_ALL_TESTS()