xref: /aosp_15_r20/external/grpc-grpc/test/core/promise/event_engine_wakeup_scheduler_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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/event_engine_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 
24 #include <grpc/event_engine/event_engine.h>
25 #include <grpc/grpc.h>
26 
27 #include "src/core/lib/gprpp/notification.h"
28 #include "src/core/lib/promise/activity.h"
29 #include "src/core/lib/promise/poll.h"
30 
31 namespace grpc_core {
32 
TEST(EventEngineWakeupSchedulerTest,Works)33 TEST(EventEngineWakeupSchedulerTest, Works) {
34   int state = 0;
35   Notification done;
36   auto activity = MakeActivity(
37       [&state]() mutable -> Poll<absl::Status> {
38         ++state;
39         switch (state) {
40           case 1:
41             return Pending();
42           case 2:
43             return absl::OkStatus();
44           default:
45             abort();
46         }
47       },
48       EventEngineWakeupScheduler(
49           grpc_event_engine::experimental::CreateEventEngine()),
50       [&done](absl::Status status) {
51         EXPECT_EQ(status, absl::OkStatus());
52         done.Notify();
53       });
54 
55   EXPECT_EQ(state, 1);
56   EXPECT_FALSE(done.HasBeenNotified());
57   activity->ForceWakeup();
58   done.WaitForNotification();
59   EXPECT_EQ(state, 2);
60 }
61 
62 }  // namespace grpc_core
63 
main(int argc,char ** argv)64 int main(int argc, char** argv) {
65   ::testing::InitGoogleTest(&argc, argv);
66   grpc_init();
67   auto r = RUN_ALL_TESTS();
68   grpc_shutdown();
69   return r;
70 }
71