MCPcopy Create free account
hub / github.com/alibaba/async_simple / TEST_F

Function TEST_F

async_simple/coro/test/ConditionVariableTest.cpp:44–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42};
43
44TEST_F(ConditionVariableTest, testSingleWait) {
45 auto data = 0;
46 Notifier notifier;
47 std::atomic<size_t> latch(2);
48
49 executors::SimpleExecutor e1(1);
50 executors::SimpleExecutor e2(1);
51
52 auto producer = [&]() -> Lazy<void> {
53 data = 1;
54 CHECK_EXECUTOR(&e2);
55 notifier.notify();
56 CHECK_EXECUTOR(&e2);
57 co_return;
58 };
59 auto awaiter = [&]() -> Lazy<void> {
60 CHECK_EXECUTOR(&e1);
61 co_await notifier.wait();
62 CHECK_EXECUTOR(&e1);
63 EXPECT_EQ(1, data);
64 data = 2;
65 co_return;
66 };
67 awaiter().via(&e1).start(
68 [&](Try<void> var) { latch.fetch_sub(1u, std::memory_order_relaxed); });
69 producer().via(&e2).start(
70 [&](Try<void> var) { latch.fetch_sub(1u, std::memory_order_relaxed); });
71 while (latch.load(std::memory_order_relaxed))
72 ;
73 EXPECT_EQ(2, data);
74}
75
76TEST_F(ConditionVariableTest, testMultiWait) {
77 auto data = 0;

Callers

nothing calls this directly

Calls 12

viaMethod · 0.80
notifyOneMethod · 0.80
notifyMethod · 0.45
waitMethod · 0.45
startMethod · 0.45
resetMethod · 0.45
coLockMethod · 0.45
unlockMethod · 0.45
coScopedLockMethod · 0.45
pushMethod · 0.45
popMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected