• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/core/lib/promise/exec_ctx_wakeup_scheduler.h"
16 
17 #include <stdlib.h>
18 
19 #include <memory>
20 
21 #include "absl/status/status.h"
22 #include "gtest/gtest.h"
23 #include "src/core/lib/promise/activity.h"
24 #include "src/core/lib/promise/poll.h"
25 
26 namespace grpc_core {
27 
TEST(ExecCtxWakeupSchedulerTest,Works)28 TEST(ExecCtxWakeupSchedulerTest, Works) {
29   int state = 0;
30   bool done = false;
31   auto activity = MakeActivity(
32       [&state]() mutable -> Poll<absl::Status> {
33         ++state;
34         switch (state) {
35           case 1:
36             return Pending();
37           case 2:
38             return absl::OkStatus();
39           default:
40             abort();
41         }
42       },
43       ExecCtxWakeupScheduler(),
44       [&done](absl::Status status) {
45         EXPECT_EQ(status, absl::OkStatus());
46         done = true;
47       });
48 
49   EXPECT_EQ(state, 1);
50   EXPECT_FALSE(done);
51   {
52     ExecCtx exec_ctx;
53     EXPECT_FALSE(exec_ctx.HasWork());
54     activity->ForceWakeup();
55     EXPECT_TRUE(exec_ctx.HasWork());
56     EXPECT_EQ(state, 1);
57     EXPECT_FALSE(done);
58   }
59   EXPECT_EQ(state, 2);
60   EXPECT_TRUE(done);
61 }
62 
63 }  // namespace grpc_core
64 
main(int argc,char ** argv)65 int main(int argc, char** argv) {
66   ::testing::InitGoogleTest(&argc, argv);
67   return RUN_ALL_TESTS();
68 }
69