Make a suite of wakeup schedulers for tests (#27459)

* Make a suite of wakeup schedulers for tests

* add missing file

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/27481/head
Craig Tiller 3 years ago committed by GitHub
parent d1cecad651
commit 65644a7bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      build_autogenerated.yaml
  2. 21
      src/core/lib/promise/activity.h
  3. 18
      test/core/promise/BUILD
  4. 14
      test/core/promise/activity_test.cc
  5. 1
      test/core/promise/for_each_test.cc
  6. 1
      test/core/promise/latch_test.cc
  7. 1
      test/core/promise/observable_test.cc
  8. 1
      test/core/promise/pipe_test.cc
  9. 64
      test/core/promise/test_wakeup_schedulers.h

@ -4304,6 +4304,7 @@ targets:
- src/core/lib/promise/promise.h
- src/core/lib/promise/seq.h
- src/core/lib/promise/wait_set.h
- test/core/promise/test_wakeup_schedulers.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -5821,6 +5822,7 @@ targets:
- src/core/lib/promise/poll.h
- src/core/lib/promise/seq.h
- src/core/lib/promise/wait_set.h
- test/core/promise/test_wakeup_schedulers.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -6435,6 +6437,7 @@ targets:
- src/core/lib/promise/latch.h
- src/core/lib/promise/poll.h
- src/core/lib/promise/seq.h
- test/core/promise/test_wakeup_schedulers.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -6726,6 +6729,7 @@ targets:
- src/core/lib/promise/promise.h
- src/core/lib/promise/seq.h
- src/core/lib/promise/wait_set.h
- test/core/promise/test_wakeup_schedulers.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -6903,6 +6907,7 @@ targets:
- src/core/lib/promise/poll.h
- src/core/lib/promise/promise.h
- src/core/lib/promise/seq.h
- test/core/promise/test_wakeup_schedulers.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c

@ -281,7 +281,7 @@ class EnterContexts : public promise_detail::Context<Contexts>... {
// There should exist a static function:
// struct WakeupScheduler {
// template <typename ActivityType>
// static void ScheduleWakeup(WakeupScheduler*, ActivityType* activity);
// void ScheduleWakeup(ActivityType* activity);
// };
// This function should arrange that activity->RunScheduledWakeup() be invoked
// at the earliest opportunity.
@ -477,25 +477,6 @@ ActivityPtr MakeActivity(Factory promise_factory,
std::move(on_done), std::move(contexts)...));
}
// A wakeup scheduler that simply crashes.
// Useful for very limited tests.
struct NoWakeupScheduler {
template <typename ActivityType>
void ScheduleWakeup(ActivityType*) {
abort();
}
};
// A wakeup scheduler that simply runs the callback immediately.
// Useful for unit testing, probably not so much for real systems due to lock
// ordering problems.
struct InlineWakeupScheduler {
template <typename ActivityType>
void ScheduleWakeup(ActivityType* activity) {
activity->RunScheduledWakeup();
}
};
} // namespace grpc_core
#endif // GRPC_CORE_LIB_PROMISE_ACTIVITY_H

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package")
load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package")
licenses(["notice"])
@ -20,6 +20,17 @@ grpc_package(name = "test/core/promise")
load("//test/core/util:grpc_fuzzer.bzl", "grpc_proto_fuzzer")
grpc_cc_library(
name = "test_wakeup_schedulers",
testonly = True,
hdrs = ["test_wakeup_schedulers.h"],
external_deps = ["gtest"],
deps = [
"//:gpr_base",
"//test/core/util:grpc_suppressions",
],
)
grpc_cc_test(
name = "poll_test",
srcs = ["poll_test.cc"],
@ -183,6 +194,7 @@ grpc_cc_test(
language = "c++",
uses_polling = False,
deps = [
"test_wakeup_schedulers",
"//:activity",
"//:join",
"//:promise",
@ -199,6 +211,7 @@ grpc_cc_test(
language = "c++",
uses_polling = False,
deps = [
"test_wakeup_schedulers",
"//:join",
"//:latch",
"//:seq",
@ -213,6 +226,7 @@ grpc_cc_test(
language = "c++",
uses_polling = False,
deps = [
"test_wakeup_schedulers",
"//:observable",
"//:promise",
"//:seq",
@ -227,6 +241,7 @@ grpc_cc_test(
language = "c++",
uses_polling = False,
deps = [
"test_wakeup_schedulers",
"//:for_each",
"//:join",
"//:map",
@ -244,6 +259,7 @@ grpc_cc_test(
language = "c++",
uses_polling = False,
deps = [
"test_wakeup_schedulers",
"//:join",
"//:pipe",
"//:promise",

@ -21,6 +21,7 @@
#include "src/core/lib/promise/promise.h"
#include "src/core/lib/promise/seq.h"
#include "src/core/lib/promise/wait_set.h"
#include "test/core/promise/test_wakeup_schedulers.h"
using testing::_;
using testing::Mock;
@ -30,19 +31,6 @@ using testing::StrictMock;
namespace grpc_core {
class MockCallbackScheduler {
public:
MOCK_METHOD(void, Schedule, (std::function<void()>));
};
struct UseMockCallbackScheduler {
MockCallbackScheduler* scheduler;
template <typename ActivityType>
void ScheduleWakeup(ActivityType* activity) {
scheduler->Schedule([activity] { activity->RunScheduledWakeup(); });
}
};
// A simple Barrier type: stalls progress until it is 'cleared'.
class Barrier {
public:

@ -22,6 +22,7 @@
#include "src/core/lib/promise/observable.h"
#include "src/core/lib/promise/pipe.h"
#include "src/core/lib/promise/seq.h"
#include "test/core/promise/test_wakeup_schedulers.h"
using testing::Mock;
using testing::MockFunction;

@ -19,6 +19,7 @@
#include "src/core/lib/promise/join.h"
#include "src/core/lib/promise/seq.h"
#include "test/core/promise/test_wakeup_schedulers.h"
using testing::MockFunction;
using testing::StrictMock;

@ -19,6 +19,7 @@
#include "src/core/lib/promise/promise.h"
#include "src/core/lib/promise/seq.h"
#include "test/core/promise/test_wakeup_schedulers.h"
using testing::MockFunction;
using testing::StrictMock;

@ -22,6 +22,7 @@
#include "src/core/lib/promise/join.h"
#include "src/core/lib/promise/promise.h"
#include "src/core/lib/promise/seq.h"
#include "test/core/promise/test_wakeup_schedulers.h"
using testing::MockFunction;
using testing::StrictMock;

@ -0,0 +1,64 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_TEST_CORE_PROMISE_TEST_WAKEUP_SCHEDULERS_H
#define GRPC_TEST_CORE_PROMISE_TEST_WAKEUP_SCHEDULERS_H
#include <gmock/gmock.h>
namespace grpc_core {
// A wakeup scheduler that simply crashes.
// Useful for very limited tests.
struct NoWakeupScheduler {
template <typename ActivityType>
void ScheduleWakeup(ActivityType*) {
abort();
}
};
// A wakeup scheduler that simply runs the callback immediately.
// Useful for unit testing, probably not so much for real systems due to lock
// ordering problems.
struct InlineWakeupScheduler {
template <typename ActivityType>
void ScheduleWakeup(ActivityType* activity) {
activity->RunScheduledWakeup();
}
};
// Mock for something that can schedule callbacks.
class MockCallbackScheduler {
public:
MOCK_METHOD(void, Schedule, (std::function<void()>));
};
// WakeupScheduler that schedules wakeups against a MockCallbackScheduler.
// Usage:
// TEST(..., ...) {
// MockCallbackScheduler scheduler;
// auto activity = MakeActivity(...,
// UseMockCallbackScheduler(&scheduler),
// ...);
struct UseMockCallbackScheduler {
MockCallbackScheduler* scheduler;
template <typename ActivityType>
void ScheduleWakeup(ActivityType* activity) {
scheduler->Schedule([activity] { activity->RunScheduledWakeup(); });
}
};
} // namespace grpc_core
#endif
Loading…
Cancel
Save