diff options
Diffstat (limited to 'test/util/thread.test.cpp')
-rw-r--r-- | test/util/thread.test.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp index 76fb5ce3f0..228e463d9e 100644 --- a/test/util/thread.test.cpp +++ b/test/util/thread.test.cpp @@ -7,6 +7,7 @@ #include <atomic> #include <memory> +#include <thread> using namespace mbgl; using namespace mbgl::util; @@ -275,3 +276,35 @@ TEST(Thread, PauseResume) { thread.actor().invoke(&TestWorker::send, [&] { loop.stop(); }); loop.run(); } + +TEST(Thread, PauseResumeMultiThreaded) { + RunLoop loop; + + // Thread to be paused + Thread<TestWorker> test("Test"); + + std::promise<void> thread1Complete; + auto future = thread1Complete.get_future(); + std::thread thread1 {[&, promise = std::move(thread1Complete)]() mutable { + // Pause the thread + test.pause(); + promise.set_value(); + }}; + + // Wait for the test thread to be paused + future.wait(); + + std::thread thread2 {[&]() { + // Pause from this thread as well and resume + test.pause(); + test.resume(); + }}; + + // Queue a message at the end of test thread's queue. + test.actor().invoke(&TestWorker::send, [&] { loop.stop(); }); + loop.run(); + + // Wait for threads + thread1.join(); + thread2.join(); +} |