Skip to content

Commit

Permalink
tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth committed Sep 11, 2023
1 parent 260c8c2 commit 16f1674
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
30 changes: 30 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/core/client_channel/lb_policy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ grpc_cc_library(
deps = [
"//src/core:lb_policy",
"//src/core:subchannel_interface",
"//test/core/event_engine:mock_event_engine",
"//test/core/event_engine/fuzzing_event_engine",
],
)

Expand Down
15 changes: 8 additions & 7 deletions test/core/client_channel/lb_policy/lb_policy_test_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1175,28 +1175,29 @@ class LoadBalancingPolicyTest : public ::testing::Test {
class TimeAwareLoadBalancingPolicyTest : public LoadBalancingPolicyTest {
protected:
TimeAwareLoadBalancingPolicyTest() {
auto fuzzing_ee =
event_engine_ =
std::make_shared<grpc_event_engine::experimental::FuzzingEventEngine>(
grpc_event_engine::experimental::FuzzingEventEngine::Options(),
fuzzing_event_engine::Actions());
// Store in base class, to make it visible to the LB policy.
event_engine_ = std::move(mock_ee);
}

~TimeAwareLoadBalancingPolicyTest() override {
EXPECT_TRUE(timer_callbacks_.empty())
<< "WARNING: Test did not run all timer callbacks";
auto* fuzzing_ee =
static_cast<grpc_event_engine::experimental::FuzzingEventEngine*>(
event_engine_.get());
fuzzing_ee->FuzzingDone();
}

void IncrementTime() {
void IncrementTimeBy(Duration duration) {
auto* fuzzing_ee =
static_cast<grpc_event_engine::experimental::FuzzingEventEngine*>(
event_engine_.get());
fuzzing_ee->Tick();
fuzzing_ee->TickForDuration(duration);
// Flush WorkSerializer, in case the timer callback enqueued anything.
WaitForWorkSerializerToFlush();
}

// FIXME
// Called when the LB policy starts a timer.
// May be overridden by subclasses.
virtual void CheckExpectedTimerDuration(
Expand Down
6 changes: 2 additions & 4 deletions test/core/client_channel/lb_policy/outlier_detection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ TEST_F(OutlierDetectionTest, FailurePercentage) {
ASSERT_TRUE(address.has_value());
gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str());
// Advance time and run the timer callback to trigger ejection.
time_cache_.IncrementBy(Duration::Seconds(10));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(10));
gpr_log(GPR_INFO, "### ejection complete");
// Expect a re-resolution request.
ExpectReresolutionRequest();
Expand Down Expand Up @@ -279,8 +278,7 @@ TEST_F(OutlierDetectionTest, DoesNotWorkWithPickFirst) {
ASSERT_TRUE(address.has_value());
gpr_log(GPR_INFO, "### failed RPC on %s", address->c_str());
// Advance time and run the timer callback to trigger ejection.
time_cache_.IncrementBy(Duration::Seconds(10));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(10));
gpr_log(GPR_INFO, "### ejection timer pass complete");
// Subchannel should not be ejected.
ExpectQueueEmpty();
Expand Down
17 changes: 6 additions & 11 deletions test/core/client_channel/lb_policy/weighted_round_robin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,8 @@ class WeightedRoundRobinTest : public TimeAwareLoadBalancingPolicyTest {
if (*picker == nullptr) return false;
} else if (run_timer_callbacks) {
gpr_log(GPR_INFO, "running timer callback...");
RunTimerCallback();
// Increment time.
time_cache_.IncrementBy(Duration::Seconds(1));
// Increment time and run any timer callbacks.
IncrementTimeBy(Duration::Seconds(1));
}
}
}
Expand Down Expand Up @@ -697,8 +696,7 @@ TEST_F(WeightedRoundRobinTest, WeightExpirationPeriod) {
{{kAddresses[0], 1}, {kAddresses[1], 3}, {kAddresses[2], 3}});
// Advance time to make weights stale and trigger the timer callback
// to recompute weights.
time_cache_.IncrementBy(Duration::Seconds(2));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(2));
// Picker should now be falling back to round-robin.
ExpectWeightedRoundRobinPicks(
picker.get(), {},
Expand All @@ -725,8 +723,7 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterWeightExpiration) {
{{kAddresses[0], 1}, {kAddresses[1], 3}, {kAddresses[2], 3}});
// Advance time to make weights stale and trigger the timer callback
// to recompute weights.
time_cache_.IncrementBy(Duration::Seconds(2));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(2));
// Picker should now be falling back to round-robin.
ExpectWeightedRoundRobinPicks(
picker.get(), {},
Expand All @@ -744,8 +741,7 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterWeightExpiration) {
{{kAddresses[0], 3}, {kAddresses[1], 3}, {kAddresses[2], 3}});
// Advance time past the blackout period. This should cause the
// weights to be used.
time_cache_.IncrementBy(Duration::Seconds(1));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(1));
ExpectWeightedRoundRobinPicks(
picker.get(), {},
{{kAddresses[0], 3}, {kAddresses[1], 3}, {kAddresses[2], 1}});
Expand Down Expand Up @@ -791,8 +787,7 @@ TEST_F(WeightedRoundRobinTest, BlackoutPeriodAfterDisconnect) {
{{kAddresses[0], 1}, {kAddresses[1], 3}, {kAddresses[2], 2}});
// Advance time to exceed the blackout period and trigger the timer
// callback to recompute weights.
time_cache_.IncrementBy(Duration::Seconds(1));
RunTimerCallback();
IncrementTimeBy(Duration::Seconds(1));
ExpectWeightedRoundRobinPicks(
picker.get(),
{{kAddresses[0], MakeBackendMetricData(/*app_utilization=*/0.3,
Expand Down

0 comments on commit 16f1674

Please sign in to comment.