4 #include "llvm/Support/Error.h"
5 #include "gmock/gmock.h"
6 #include "gtest/gtest.h"
15 TEST(CancellationTest, CancellationTest) {
17 WithContext ContextWithCancellation(std::move(Task.first));
23 TEST(CancellationTest, CancelerDiesContextLives) {
24 llvm::Optional<WithContext> ContextWithCancellation;
27 ContextWithCancellation.emplace(std::move(Task.first));
35 TEST(CancellationTest, TaskContextDiesHandleLives) {
38 WithContext ContextWithCancellation(std::move(Task.first));
48 enum { OuterReason = 1, InnerReason = 2 };
53 WithContext WithOuter(
Outer.first.clone());
59 TEST(CancellationTest, Nested) {
61 NestedTasks CancelInner;
62 CancelInner.Inner.second();
63 EXPECT_EQ(NestedTasks::InnerReason,
isCancelled(CancelInner.Inner.first));
66 NestedTasks CancelOuter;
67 CancelOuter.Outer.second();
68 EXPECT_EQ(NestedTasks::OuterReason,
isCancelled(CancelOuter.Inner.first));
69 EXPECT_EQ(NestedTasks::OuterReason,
isCancelled(CancelOuter.Outer.first));
72 TEST(CancellationTest, AsynCancellationTest) {
73 std::atomic<bool> HasCancelled(
false);
74 Notification Cancelled;
75 auto TaskToBeCancelled = [&](Context
Ctx) {
76 WithContext ContextGuard(std::move(
Ctx));
81 std::thread AsyncTask(TaskToBeCancelled, std::move(Task.first));
86 EXPECT_TRUE(HasCancelled);