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