summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp')
-rw-r--r--vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp77
1 files changed, 56 insertions, 21 deletions
diff --git a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp
index fa2c525b518..0689909da09 100644
--- a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp
+++ b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
LOG_SETUP("generation_handler_stress_test");
-#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/util/generationhandler.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <vespa/vespalib/util/size_literals.h>
@@ -10,6 +10,12 @@ using vespalib::Executor;
using vespalib::GenerationHandler;
using vespalib::ThreadStackExecutor;
+namespace {
+
+bool smoke_test = false;
+const vespalib::string smoke_test_option = "--smoke-test";
+
+}
struct WorkContext
{
@@ -21,26 +27,28 @@ struct WorkContext
}
};
-struct Fixture {
+class Fixture : public ::testing::Test {
+protected:
GenerationHandler _generationHandler;
uint32_t _readThreads;
ThreadStackExecutor _writer; // 1 write thread
- ThreadStackExecutor _readers; // multiple reader threads
+ std::unique_ptr<ThreadStackExecutor> _readers; // multiple reader threads
std::atomic<long> _readSeed;
std::atomic<long> _doneWriteWork;
std::atomic<long> _doneReadWork;
std::atomic<int> _stopRead;
bool _reportWork;
- Fixture(uint32_t readThreads = 1);
-
+ Fixture();
~Fixture();
- void readWork(const WorkContext &context);
- void writeWork(uint32_t cnt, WorkContext &context);
+ void set_read_threads(uint32_t read_threads);
+
uint32_t getReadThreads() const { return _readThreads; }
void stressTest(uint32_t writeCnt);
-
+public:
+ void readWork(const WorkContext &context);
+ void writeWork(uint32_t cnt, WorkContext &context);
private:
Fixture(const Fixture &index) = delete;
Fixture(Fixture &&index) = delete;
@@ -49,23 +57,27 @@ private:
};
-Fixture::Fixture(uint32_t readThreads)
- : _generationHandler(),
- _readThreads(readThreads),
+Fixture::Fixture()
+ : ::testing::Test(),
+ _generationHandler(),
+ _readThreads(1),
_writer(1, 128_Ki),
- _readers(readThreads, 128_Ki),
+ _readers(),
_doneWriteWork(0),
_doneReadWork(0),
_stopRead(0),
_reportWork(false)
{
+ set_read_threads(1);
}
Fixture::~Fixture()
{
- _readers.sync();
- _readers.shutdown();
+ if (_readers) {
+ _readers->sync();
+ _readers->shutdown();
+ }
_writer.sync();
_writer.shutdown();
if (_reportWork) {
@@ -75,6 +87,16 @@ Fixture::~Fixture()
}
}
+void
+Fixture::set_read_threads(uint32_t read_threads)
+{
+ if (_readers) {
+ _readers->sync();
+ _readers->shutdown();
+ }
+ _readThreads = read_threads;
+ _readers = std::make_unique<ThreadStackExecutor>(read_threads, 128_Ki);
+}
void
Fixture::readWork(const WorkContext &context)
@@ -85,7 +107,7 @@ Fixture::readWork(const WorkContext &context)
for (i = 0; i < cnt && _stopRead.load() == 0; ++i) {
auto guard = _generationHandler.takeGuard();
auto generation = context._generation.load(std::memory_order_relaxed);
- EXPECT_GREATER_EQUAL(generation, guard.getGeneration());
+ EXPECT_GE(generation, guard.getGeneration());
}
_doneReadWork += i;
LOG(info, "done %u read work", i);
@@ -150,19 +172,32 @@ Fixture::stressTest(uint32_t writeCnt)
auto context = std::make_shared<WorkContext>();
_writer.execute(std::make_unique<WriteWorkTask>(*this, writeCnt, context));
for (uint32_t i = 0; i < readThreads; ++i) {
- _readers.execute(std::make_unique<ReadWorkTask>(*this, context));
+ _readers->execute(std::make_unique<ReadWorkTask>(*this, context));
}
+ _writer.sync();
+ _readers->sync();
}
+using GenerationHandlerStressTest = Fixture;
-TEST_F("stress test, 2 readers", Fixture(2))
+TEST_F(GenerationHandlerStressTest, stress_test_2_readers)
{
- f.stressTest(1000000);
+ set_read_threads(2);
+ stressTest(smoke_test ? 10000 : 1000000);
}
-TEST_F("stress test, 4 readers", Fixture(4))
+TEST_F(GenerationHandlerStressTest, stress_test_4_readers)
{
- f.stressTest(1000000);
+ set_read_threads(4);
+ stressTest(smoke_test ? 10000 : 1000000);
}
-TEST_MAIN() { TEST_RUN_ALL(); }
+int main(int argc, char **argv) {
+ if (argc > 1 && argv[1] == smoke_test_option) {
+ smoke_test = true;
+ ++argv;
+ --argc;
+ }
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}