summaryrefslogtreecommitdiffstats
path: root/storage/src/tests
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-01-21 09:35:12 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-01-21 12:34:35 +0000
commit5ced8942ecd76da46fa2d6c70a19cc9d302a1110 (patch)
tree57f5a546b30f3b7ed2b6ccd1d0620885e728e289 /storage/src/tests
parent690d90ceb13797e1ff7876d4e9fc24efbec5f57b (diff)
Replace storage operation throttler with vespalib implementation
Also move the remaining throttler unit tests to vespalib.
Diffstat (limited to 'storage/src/tests')
-rw-r--r--storage/src/tests/persistence/CMakeLists.txt1
-rw-r--r--storage/src/tests/persistence/shared_operation_throttler_test.cpp116
2 files changed, 0 insertions, 117 deletions
diff --git a/storage/src/tests/persistence/CMakeLists.txt b/storage/src/tests/persistence/CMakeLists.txt
index fb8120210c1..7b165e11b66 100644
--- a/storage/src/tests/persistence/CMakeLists.txt
+++ b/storage/src/tests/persistence/CMakeLists.txt
@@ -12,7 +12,6 @@ vespa_add_executable(storage_persistence_gtest_runner_app TEST
persistencethread_splittest.cpp
processalltest.cpp
provider_error_wrapper_test.cpp
- shared_operation_throttler_test.cpp
splitbitdetectortest.cpp
testandsettest.cpp
gtest_runner.cpp
diff --git a/storage/src/tests/persistence/shared_operation_throttler_test.cpp b/storage/src/tests/persistence/shared_operation_throttler_test.cpp
deleted file mode 100644
index 0ad380937c7..00000000000
--- a/storage/src/tests/persistence/shared_operation_throttler_test.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/storage/persistence/shared_operation_throttler.h>
-#include <vespa/vespalib/gtest/gtest.h>
-#include <vespa/vespalib/util/barrier.h>
-#include <chrono>
-#include <thread>
-
-using namespace ::testing;
-
-namespace storage {
-
-using ThrottleToken = SharedOperationThrottler::Token;
-
-TEST(SharedOperationThrottlerTest, unlimited_throttler_does_not_throttle) {
- // We technically can't test that the unlimited throttler _never_ throttles, but at
- // least check that it doesn't throttle _twice_, and then induce from this ;)
- auto throttler = SharedOperationThrottler::make_unlimited_throttler();
- auto token1 = throttler->try_acquire_one();
- EXPECT_TRUE(token1.valid());
- auto token2 = throttler->blocking_acquire_one();
- EXPECT_TRUE(token2.valid());
- // Window size should be zero (i.e. unlimited) for unlimited throttler
- EXPECT_EQ(throttler->current_window_size(), 0);
-}
-
-TEST(SharedOperationThrottlerTest, dynamic_throttler_respects_initial_window_size) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- auto token1 = throttler->try_acquire_one();
- EXPECT_TRUE(token1.valid());
- auto token2 = throttler->try_acquire_one();
- EXPECT_FALSE(token2.valid());
-
- EXPECT_EQ(throttler->current_window_size(), 1);
-}
-
-TEST(SharedOperationThrottlerTest, blocking_acquire_returns_immediately_if_slot_available) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- auto token = throttler->blocking_acquire_one();
- EXPECT_TRUE(token.valid());
- token.reset();
- token = throttler->blocking_acquire_one(600s); // Should never block.
- EXPECT_TRUE(token.valid());
-}
-
-TEST(SharedOperationThrottlerTest, blocking_call_woken_up_if_throttle_slot_available) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- vespalib::Barrier barrier(2);
- std::thread t([&] {
- auto token = throttler->try_acquire_one();
- assert(token.valid());
- barrier.await();
- while (throttler->waiting_threads() != 1) {
- std::this_thread::sleep_for(100us);
- }
- // Implicit token release at thread scope exit
- });
- barrier.await();
- auto token = throttler->blocking_acquire_one();
- EXPECT_TRUE(token.valid());
- t.join();
-}
-
-TEST(SharedOperationThrottlerTest, time_bounded_blocking_acquire_waits_for_timeout) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- auto window_filling_token = throttler->try_acquire_one();
- auto before = std::chrono::steady_clock::now();
- // Will block for at least 1ms. Since no window slot will be available by that time,
- // an invalid token should be returned.
- auto token = throttler->blocking_acquire_one(1ms);
- auto after = std::chrono::steady_clock::now();
- EXPECT_TRUE((after - before) >= 1ms);
- EXPECT_FALSE(token.valid());
-}
-
-TEST(SharedOperationThrottlerTest, default_constructed_token_is_invalid) {
- ThrottleToken token;
- EXPECT_FALSE(token.valid());
- token.reset(); // no-op
- EXPECT_FALSE(token.valid());
-}
-
-TEST(SharedOperationThrottlerTest, token_destruction_frees_up_throttle_window_slot) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- {
- auto token = throttler->try_acquire_one();
- EXPECT_TRUE(token.valid());
- }
- auto token = throttler->try_acquire_one();
- EXPECT_TRUE(token.valid());
-}
-
-TEST(SharedOperationThrottlerTest, token_can_be_moved_and_reset) {
- auto throttler = SharedOperationThrottler::make_dynamic_throttler(1);
- auto token1 = throttler->try_acquire_one();
- auto token2 = std::move(token1); // move ctor
- EXPECT_TRUE(token2.valid());
- EXPECT_FALSE(token1.valid());
- ThrottleToken token3;
- token3 = std::move(token2); // move assignment op
- EXPECT_TRUE(token3.valid());
- EXPECT_FALSE(token2.valid());
-
- // Trying to fetch new token should not succeed due to active token and win size of 1
- token1 = throttler->try_acquire_one();
- EXPECT_FALSE(token1.valid());
- // Resetting the token should free up the slot in the window
- token3.reset();
- token1 = throttler->try_acquire_one();
- EXPECT_TRUE(token1.valid());
-}
-
-// TODO ideally we'd test that the dynamic throttler has a window size that is actually
-// dynamic, but the backing DynamicThrottlePolicy implementation is a black box so
-// it's not trivial to know how to do this reliably.
-
-}