diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/util/thread.test.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp index 76fb5ce3f0..c74dae2ec6 100644 --- a/test/util/thread.test.cpp +++ b/test/util/thread.test.cpp @@ -275,3 +275,57 @@ TEST(Thread, PauseResume) { thread.actor().invoke(&TestWorker::send, [&] { loop.stop(); }); loop.run(); } + +TEST(Thread, MultiplePauseResumeCalls) { + RunLoop loop; + + Thread<TestWorker> thread("Test"); + + // Test if multiple pause calls work + thread.pause(); + thread.pause(); + thread.resume(); + thread.resume(); + + thread.actor().invoke(&TestWorker::send, [&] { loop.stop(); }); + loop.run(); +} + +TEST(Thread, TestImmediatePause) { + using namespace std::chrono_literals; + + RunLoop loop; + + Thread<TestWorker> thread("Test"); + + std::promise<void> resume; + auto resumed = resume.get_future(); + + std::atomic<bool> ending { false }; + + thread.pause(); + thread.actor().invoke(&TestWorker::send, [&] { + resume.set_value(); + + // Make sure we have some time to process the pause() call. + std::this_thread::sleep_for(300ms); + }); + + // We're scheduling a second action right after, before calling pause. Ensure that it never + // gets called. + thread.actor().invoke(&TestWorker::send, [&] { + EXPECT_TRUE(ending) << "callback called without ending"; + }); + + thread.resume(); + resumed.get(); + thread.pause(); + + Timer timer; + timer.start(600ms, Duration::zero(), [&] { + ending = true; + loop.stop(); + }); + + loop.run(); +} |