proxygen
BatonTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/Portability.h>
17 
18 #if FOLLY_HAS_COROUTINES
19 
24 
25 using namespace folly;
26 
27 TEST(Baton, Ready) {
28  coro::Baton b;
29  CHECK(!b.ready());
30  b.post();
31  CHECK(b.ready());
32  b.reset();
33  CHECK(!b.ready());
34 }
35 
36 TEST(Baton, InitiallyReady) {
37  coro::Baton b{true};
38  CHECK(b.ready());
39  b.reset();
40  CHECK(!b.ready());
41 }
42 
43 TEST(Baton, AwaitBaton) {
44  coro::Baton baton;
45  bool reachedBeforeAwait = false;
46  bool reachedAfterAwait = false;
47 
48  auto makeTask = [&]() -> coro::Task<void> {
49  reachedBeforeAwait = true;
50  co_await baton;
51  reachedAfterAwait = true;
52  };
53 
54  coro::Task<void> t = makeTask();
55 
56  CHECK(!reachedBeforeAwait);
57  CHECK(!reachedAfterAwait);
58 
59  auto f = std::move(t).scheduleOn(&InlineExecutor::instance()).start();
60 
61  CHECK(reachedBeforeAwait);
62  CHECK(!reachedAfterAwait);
63 
64  baton.post();
65 
66  CHECK(reachedAfterAwait);
67 }
68 
69 #endif
auto f
char b
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void post() noexcept
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
bool ready() const noexcept
Query whether the Baton is currently in the signalled state.
Definition: Baton.h:135
TEST(SequencedExecutor, CPUThreadPoolExecutor)
void reset() noexcept
Definition: Baton.h:144