4#include "gmock/gmock.h"
5#include "gtest/gtest.h"
15TEST(CancellationTest, CancellationTest) {
17 WithContext ContextWithCancellation(std::move(Task.first));
23TEST(CancellationTest, CancelerDiesContextLives) {
24 std::optional<WithContext> ContextWithCancellation;
27 ContextWithCancellation.emplace(std::move(Task.first));
35TEST(CancellationTest, TaskContextDiesHandleLives) {
38 WithContext ContextWithCancellation(std::move(Task.first));
48 enum { OuterReason = 1, InnerReason = 2 };
49 std::pair<Context, Canceler> Outer, Inner;
53 WithContext WithOuter(Outer.first.clone());
59TEST(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));
72TEST(CancellationTest, AsynCancellationTest) {
73 std::atomic<bool> HasCancelled(
false);
75 auto TaskToBeCancelled = [&](
Context Ctx) {
81 std::thread AsyncTask(TaskToBeCancelled, std::move(Task.first));
86 EXPECT_TRUE(HasCancelled);
A context is an immutable container for per-request data that must be propagated through layers that ...
A threadsafe flag that is initially clear.
WithContext replaces Context::current() with a provided scope.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
TEST(BackgroundQueueTest, Priority)
std::pair< Context, Canceler > cancelableTask(int Reason)
Defines a new task whose cancellation may be requested.
int isCancelled(const Context &Ctx)
If the current context is within a cancelled task, returns the reason.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//