test_wakeup_schedulers.h
Go to the documentation of this file.
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 #ifndef GRPC_TEST_CORE_PROMISE_TEST_WAKEUP_SCHEDULERS_H
16 #define GRPC_TEST_CORE_PROMISE_TEST_WAKEUP_SCHEDULERS_H
17 
18 #include <stdlib.h>
19 
20 #include <functional>
21 
22 #include "gmock/gmock.h"
23 
24 namespace grpc_core {
25 
26 // A wakeup scheduler that simply crashes.
27 // Useful for very limited tests.
29  template <typename ActivityType>
30  void ScheduleWakeup(ActivityType*) {
31  abort();
32  }
33 };
34 
35 // A wakeup scheduler that simply runs the callback immediately.
36 // Useful for unit testing, probably not so much for real systems due to lock
37 // ordering problems.
39  template <typename ActivityType>
40  void ScheduleWakeup(ActivityType* activity) {
41  activity->RunScheduledWakeup();
42  }
43 };
44 
45 // Mock for something that can schedule callbacks.
47  public:
48  MOCK_METHOD(void, Schedule, (std::function<void()>));
49 };
50 
51 // WakeupScheduler that schedules wakeups against a MockCallbackScheduler.
52 // Usage:
53 // TEST(..., ...) {
54 // MockCallbackScheduler scheduler;
55 // auto activity = MakeActivity(...,
56 // UseMockCallbackScheduler(&scheduler),
57 // ...);
60  template <typename ActivityType>
61  void ScheduleWakeup(ActivityType* activity) {
62  scheduler->Schedule([activity] { activity->RunScheduledWakeup(); });
63  }
64 };
65 
66 } // namespace grpc_core
67 
68 #endif
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MockCallbackScheduler::MOCK_METHOD
MOCK_METHOD(void, Schedule,(std::function< void()>))
grpc_core::UseMockCallbackScheduler::scheduler
MockCallbackScheduler * scheduler
Definition: test_wakeup_schedulers.h:59
grpc_core::InlineWakeupScheduler
Definition: test_wakeup_schedulers.h:38
grpc_core::InlineWakeupScheduler::ScheduleWakeup
void ScheduleWakeup(ActivityType *activity)
Definition: test_wakeup_schedulers.h:40
grpc_core::UseMockCallbackScheduler::ScheduleWakeup
void ScheduleWakeup(ActivityType *activity)
Definition: test_wakeup_schedulers.h:61
grpc_core::MockCallbackScheduler
Definition: test_wakeup_schedulers.h:46
grpc_core::UseMockCallbackScheduler
Definition: test_wakeup_schedulers.h:58
grpc_core::NoWakeupScheduler
Definition: test_wakeup_schedulers.h:28
grpc_core::NoWakeupScheduler::ScheduleWakeup
void ScheduleWakeup(ActivityType *)
Definition: test_wakeup_schedulers.h:30
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:32