summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/executor
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2016-08-30 13:06:02 +0000
committerHaavard <havardpe@yahoo-inc.com>2016-08-30 13:06:02 +0000
commitbf1049fd28e584f7938c33a1d682f78aaa4a2746 (patch)
tree23aa58833886bab18e3658e5a2d59e272c618ad0 /vespalib/src/tests/executor
parent40d64bb42736bd19a792c9b9c58b578b1b540f20 (diff)
added small stress test for blocking thread stack executor
(scaled down to be nice to valgrind)
Diffstat (limited to 'vespalib/src/tests/executor')
-rw-r--r--vespalib/src/tests/executor/.gitignore1
-rw-r--r--vespalib/src/tests/executor/CMakeLists.txt7
-rw-r--r--vespalib/src/tests/executor/blocking_executor_stress.cpp52
3 files changed, 60 insertions, 0 deletions
diff --git a/vespalib/src/tests/executor/.gitignore b/vespalib/src/tests/executor/.gitignore
index 33760771905..96203a03956 100644
--- a/vespalib/src/tests/executor/.gitignore
+++ b/vespalib/src/tests/executor/.gitignore
@@ -7,3 +7,4 @@ vespalib_executor_test_app
vespalib_stress_test_app
vespalib_threadstackexecutor_test_app
/vespalib_blockingthreadstackexecutor_test_app
+/vespalib_blocking_executor_stress_test_app
diff --git a/vespalib/src/tests/executor/CMakeLists.txt b/vespalib/src/tests/executor/CMakeLists.txt
index 0435c03f34c..54ca828d89a 100644
--- a/vespalib/src/tests/executor/CMakeLists.txt
+++ b/vespalib/src/tests/executor/CMakeLists.txt
@@ -27,3 +27,10 @@ vespa_add_executable(vespalib_blockingthreadstackexecutor_test_app TEST
vespalib
)
vespa_add_test(NAME vespalib_blockingthreadstackexecutor_test_app COMMAND vespalib_blockingthreadstackexecutor_test_app)
+vespa_add_executable(vespalib_blocking_executor_stress_test_app TEST
+ SOURCES
+ blocking_executor_stress.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_blocking_executor_stress_test_app COMMAND vespalib_blocking_executor_stress_test_app)
diff --git a/vespalib/src/tests/executor/blocking_executor_stress.cpp b/vespalib/src/tests/executor/blocking_executor_stress.cpp
new file mode 100644
index 00000000000..4adecb7c4a9
--- /dev/null
+++ b/vespalib/src/tests/executor/blocking_executor_stress.cpp
@@ -0,0 +1,52 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/util/blockingthreadstackexecutor.h>
+#include <vespa/vespalib/util/executor.h>
+#include <vespa/vespalib/util/sync.h>
+#include <atomic>
+
+using namespace vespalib;
+
+std::atomic<size_t> tasks_run;
+
+size_t do_stuff(size_t size) {
+ size_t value = 0;
+ for (size_t i = 0; i < size; ++i) {
+ for (size_t j = 0; j < i; ++j) {
+ for (size_t k = 0; k < j; ++k) {
+ value += (i * j * k);
+ value *= (i + j + k);
+ }
+ }
+ }
+ return value;
+}
+
+struct MyTask : Executor::Task {
+ size_t size;
+ size_t data;
+ MyTask(size_t size_in) : size(size_in), data(0) {}
+ virtual void run() override {
+ data += do_stuff(size);
+ ++tasks_run;
+ data += do_stuff(size);
+ data += do_stuff(size);
+ }
+};
+
+TEST_MT_F("stress test block thread stack executor", 8, BlockingThreadStackExecutor(4, 128000, 1000))
+{
+ size_t loop_cnt = 100;
+ for (size_t i = 0; i < loop_cnt; ++i) {
+ auto result = f1.execute(std::make_unique<MyTask>(thread_id));
+ EXPECT_TRUE(result.get() == nullptr);
+ }
+ TEST_BARRIER();
+ if (thread_id == 0) {
+ f1.shutdown().sync();
+ }
+ TEST_BARRIER();
+ EXPECT_EQUAL((loop_cnt * num_threads), tasks_run);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }