From 16f1674d37ba061dd596cb98c4f37b0e469ff78c Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 11 Sep 2023 17:38:37 +0000 Subject: [PATCH] tests working --- CMakeLists.txt | 30 +++++++++++++++++++ build_autogenerated.yaml | 25 ++++++++++++---- test/core/client_channel/lb_policy/BUILD | 2 +- .../lb_policy/lb_policy_test_lib.h | 15 +++++----- .../lb_policy/outlier_detection_test.cc | 6 ++-- .../lb_policy/weighted_round_robin_test.cc | 17 ++++------- 6 files changed, 67 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e52b615d40d7..6dc00f16c8c64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16686,7 +16686,12 @@ endif() if(gRPC_BUILD_TESTS) add_executable(outlier_detection_test + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.h test/core/client_channel/lb_policy/outlier_detection_test.cc + test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc ) target_compile_features(outlier_detection_test PUBLIC cxx_std_14) target_include_directories(outlier_detection_test @@ -16711,6 +16716,7 @@ target_include_directories(outlier_detection_test target_link_libraries(outlier_detection_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + ${_gRPC_PROTOBUF_LIBRARIES} grpc_test_util ) @@ -17068,7 +17074,12 @@ endif() if(gRPC_BUILD_TESTS) add_executable(pick_first_test + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.h test/core/client_channel/lb_policy/pick_first_test.cc + test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc ) target_compile_features(pick_first_test PUBLIC cxx_std_14) target_include_directories(pick_first_test @@ -17093,6 +17104,7 @@ target_include_directories(pick_first_test target_link_libraries(pick_first_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + ${_gRPC_PROTOBUF_LIBRARIES} grpc_test_util ) @@ -20610,7 +20622,12 @@ endif() if(gRPC_BUILD_TESTS) add_executable(round_robin_test + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.h test/core/client_channel/lb_policy/round_robin_test.cc + test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc ) target_compile_features(round_robin_test PUBLIC cxx_std_14) target_include_directories(round_robin_test @@ -20635,6 +20652,7 @@ target_include_directories(round_robin_test target_link_libraries(round_robin_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + ${_gRPC_PROTOBUF_LIBRARIES} grpc_test_util ) @@ -25475,7 +25493,12 @@ endif() if(gRPC_BUILD_TESTS) add_executable(weighted_round_robin_test + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.h test/core/client_channel/lb_policy/weighted_round_robin_test.cc + test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc ) target_compile_features(weighted_round_robin_test PUBLIC cxx_std_14) target_include_directories(weighted_round_robin_test @@ -25500,6 +25523,7 @@ target_include_directories(weighted_round_robin_test target_link_libraries(weighted_round_robin_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + ${_gRPC_PROTOBUF_LIBRARIES} grpc_test_util ) @@ -28513,7 +28537,12 @@ endif() if(gRPC_BUILD_TESTS) add_executable(xds_override_host_test + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.pb.h + ${_gRPC_PROTO_GENS_DIR}/test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.grpc.pb.h test/core/client_channel/lb_policy/xds_override_host_test.cc + test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc ) target_compile_features(xds_override_host_test PUBLIC cxx_std_14) target_include_directories(xds_override_host_test @@ -28538,6 +28567,7 @@ target_include_directories(xds_override_host_test target_link_libraries(xds_override_host_test ${_gRPC_ALLTARGETS_LIBRARIES} gtest + ${_gRPC_PROTOBUF_LIBRARIES} grpc_test_util ) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index efa73d0d07cd9..ecc37cf7cd4f4 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -11346,11 +11346,14 @@ targets: language: c++ headers: - test/core/client_channel/lb_policy/lb_policy_test_lib.h - - test/core/event_engine/mock_event_engine.h + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h src: + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto - test/core/client_channel/lb_policy/outlier_detection_test.cc + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc deps: - gtest + - protobuf - grpc_test_util uses_polling: false - name: overload_test @@ -11572,12 +11575,15 @@ targets: language: c++ headers: - test/core/client_channel/lb_policy/lb_policy_test_lib.h - - test/core/event_engine/mock_event_engine.h + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h - test/core/util/scoped_env_var.h src: + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto - test/core/client_channel/lb_policy/pick_first_test.cc + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc deps: - gtest + - protobuf - grpc_test_util uses_polling: false - name: pid_controller_test @@ -13911,11 +13917,14 @@ targets: language: c++ headers: - test/core/client_channel/lb_policy/lb_policy_test_lib.h - - test/core/event_engine/mock_event_engine.h + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h src: + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto - test/core/client_channel/lb_policy/round_robin_test.cc + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc deps: - gtest + - protobuf - grpc_test_util uses_polling: false - name: secure_auth_context_test @@ -16842,11 +16851,14 @@ targets: language: c++ headers: - test/core/client_channel/lb_policy/lb_policy_test_lib.h - - test/core/event_engine/mock_event_engine.h + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h src: + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto - test/core/client_channel/lb_policy/weighted_round_robin_test.cc + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc deps: - gtest + - protobuf - grpc_test_util uses_polling: false - name: win_socket_test @@ -18160,11 +18172,14 @@ targets: language: c++ headers: - test/core/client_channel/lb_policy/lb_policy_test_lib.h - - test/core/event_engine/mock_event_engine.h + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.h src: + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.proto - test/core/client_channel/lb_policy/xds_override_host_test.cc + - test/core/event_engine/fuzzing_event_engine/fuzzing_event_engine.cc deps: - gtest + - protobuf - grpc_test_util uses_polling: false - name: xds_pick_first_end2end_test diff --git a/test/core/client_channel/lb_policy/BUILD b/test/core/client_channel/lb_policy/BUILD index 8f5bc0ff4cb1a..2d382a01976eb 100644 --- a/test/core/client_channel/lb_policy/BUILD +++ b/test/core/client_channel/lb_policy/BUILD @@ -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", ], ) diff --git a/test/core/client_channel/lb_policy/lb_policy_test_lib.h b/test/core/client_channel/lb_policy/lb_policy_test_lib.h index 73c6a00c53075..96610bc9b94aa 100644 --- a/test/core/client_channel/lb_policy/lb_policy_test_lib.h +++ b/test/core/client_channel/lb_policy/lb_policy_test_lib.h @@ -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::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( + event_engine_.get()); + fuzzing_ee->FuzzingDone(); } - void IncrementTime() { + void IncrementTimeBy(Duration duration) { auto* fuzzing_ee = static_cast( 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( diff --git a/test/core/client_channel/lb_policy/outlier_detection_test.cc b/test/core/client_channel/lb_policy/outlier_detection_test.cc index ea3c0a477c2cf..c3115a15fe5e2 100644 --- a/test/core/client_channel/lb_policy/outlier_detection_test.cc +++ b/test/core/client_channel/lb_policy/outlier_detection_test.cc @@ -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(); @@ -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(); diff --git a/test/core/client_channel/lb_policy/weighted_round_robin_test.cc b/test/core/client_channel/lb_policy/weighted_round_robin_test.cc index f1383334ac576..92fe65a92d3b2 100644 --- a/test/core/client_channel/lb_policy/weighted_round_robin_test.cc +++ b/test/core/client_channel/lb_policy/weighted_round_robin_test.cc @@ -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)); } } } @@ -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(), {}, @@ -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(), {}, @@ -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}}); @@ -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,