From 1f798e899a1cb52e6faa5c993d07ddf2bc514e96 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 6 Oct 2022 15:25:10 -0700 Subject: [PATCH] [dns] Fix test race (#31270) --- .../resolvers/dns_resolver_cooldown_test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc index b80ef2d82aa..0be3f1cf12d 100644 --- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc @@ -42,6 +42,8 @@ #include "src/core/lib/config/core_configuration.h" #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/debug_location.h" +#include "src/core/lib/gprpp/no_destruct.h" +#include "src/core/lib/gprpp/notification.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/time.h" #include "src/core/lib/gprpp/work_serializer.h" @@ -297,7 +299,7 @@ struct OnResolutionCallbackArg { }; // Set to true by the last callback in the resolution chain. -static bool g_all_callbacks_invoked; +static grpc_core::NoDestruct g_all_callbacks_invoked; // It's interesting to run a few rounds of this test because as // we run more rounds, the base starting time @@ -314,7 +316,7 @@ static void on_fourth_resolution(OnResolutionCallbackArg* cb_arg) { grpc_pollset_kick(g_iomgr_args.pollset, nullptr)); gpr_mu_unlock(g_iomgr_args.mu); delete cb_arg; - g_all_callbacks_invoked = true; + g_all_callbacks_invoked->Notify(); } static void on_third_resolution(OnResolutionCallbackArg* cb_arg) { @@ -416,7 +418,7 @@ TEST(DnsResolverCooldownTest, MainTest) { test_cooldown(); grpc_shutdown(); - ASSERT_TRUE(g_all_callbacks_invoked); + g_all_callbacks_invoked->WaitForNotification(); } int main(int argc, char** argv) {