diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-09-14 17:43:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 17:43:20 +0200 |
commit | 58ce86bd1a8006c49f8286bfb73ba0f56276f2fb (patch) | |
tree | b0b2bf1e0eeaf8adac6e06d4a5a66c7b64ae3044 /vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp | |
parent | 4840ba81903a4f030c2541b805124cc0eb271e3a (diff) | |
parent | 92649edc2b02a8615f2cdff162deef5c1d9ce337 (diff) |
Merge pull request #24056 from vespa-engine/havardpe/more-convenient-thread-bundlev8.53.21
more convenient ThreadBundle::run
Diffstat (limited to 'vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp')
-rw-r--r-- | vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp index debb34724f6..d6e0e473e59 100644 --- a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp @@ -201,4 +201,54 @@ TEST_MT_FF("require that bundle pool works with multiple threads", 32, SimpleThr f1.release(std::move(bundle)); } +struct Filler { + int stuff; + Filler() : stuff(0) {} + virtual ~Filler() {} +}; + +struct Proxy : Filler, Runnable { + Runnable ⌖ + Proxy(Runnable &target_in) : target(target_in) {} + void run() override { target.run(); } +}; + +struct AlmostRunnable : Runnable {}; + +TEST("require that Proxy needs fixup to become Runnable") { + Cnt cnt; + Proxy proxy(cnt); + Runnable &runnable = proxy; + void *proxy_ptr = &proxy; + void *runnable_ptr = &runnable; + EXPECT_TRUE(proxy_ptr != runnable_ptr); +} + +TEST_FF("require that various versions of run can be used to invoke targets", SimpleThreadBundle(5), State(5)) { + EXPECT_TRUE(ThreadBundle::is_runnable_ptr<Runnable*>()); + EXPECT_TRUE(ThreadBundle::is_runnable_ptr<Runnable::UP>()); + EXPECT_FALSE(ThreadBundle::is_runnable_ptr<std::unique_ptr<Proxy>>()); + EXPECT_FALSE(ThreadBundle::is_runnable_ptr<std::unique_ptr<AlmostRunnable>>()); + std::vector<Runnable::UP> direct; + std::vector<std::unique_ptr<Proxy>> custom; + for (Runnable &target: f2.cnts) { + direct.push_back(std::make_unique<Proxy>(target)); + custom.push_back(std::make_unique<Proxy>(target)); + } + std::vector<Runnable*> refs = f2.getTargets(5); + f2.check({0,0,0,0,0}); + f1.run(refs.data(), 3); + f2.check({1,1,1,0,0}); + f1.run(&refs[3], 2); + f2.check({1,1,1,1,1}); + f1.run(refs); + f2.check({2,2,2,2,2}); + f1.run(direct); + f2.check({3,3,3,3,3}); + f1.run(custom); + f2.check({4,4,4,4,4}); + f1.run(f2.cnts); + f2.check({5,5,5,5,5}); +} + TEST_MAIN() { TEST_RUN_ALL(); } |