From 618b9f1dbff9c3a13c886b0edd949b7c6533fc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 12 Apr 2016 12:00:11 -0700 Subject: [darwin] use CFRunLoopSourceInvalidate() to also cancel any pending AsyncTask invocations --- test/util/async_task.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/util') diff --git a/test/util/async_task.cpp b/test/util/async_task.cpp index 9d36230472..5fd890ad9e 100644 --- a/test/util/async_task.cpp +++ b/test/util/async_task.cpp @@ -64,6 +64,33 @@ TEST(AsyncTask, DestroyShouldNotRunQueue) { EXPECT_EQ(count, 0); } +TEST(AsyncTask, DestroyAfterSignaling) { + RunLoop loop; + + // We're creating two tasks and signal both of them; the one that gets fired first destroys + // the other one. Make sure that the second one we destroyed doesn't fire. + + std::unique_ptr task1, task2; + + task1 = std::make_unique([&] { + task2.reset(); + if (!task1) { + FAIL() << "Task was destroyed but invoked anyway"; + } + }); + task2 = std::make_unique([&] { + task1.reset(); + if (!task2) { + FAIL() << "Task was destroyed but invoked anyway"; + } + }); + + task1->send(); + task2->send(); + + loop.runOnce(); +} + TEST(AsyncTask, RequestCoalescingMultithreaded) { RunLoop loop; -- cgit v1.2.1