From feeb54ec33c28752c01dd1cba33579cf9f1f6ee4 Mon Sep 17 00:00:00 2001 From: Cheng-Yu Chung Date: Wed, 17 Aug 2022 19:32:29 -0400 Subject: [PATCH] [fixit] Fix flakiness for test case ChannelzSamplerTest.SimpleTest by reducing the chance of port conflict (#30620) * Fix flakiness for test case ChannelzSamplerTest.SimpleTest by reducing the chance of port conflict * Update --- test/cpp/util/BUILD | 1 + test/cpp/util/channelz_sampler_test.cc | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 00d22edcf03..d6ea4e10b88 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -332,6 +332,7 @@ grpc_cc_binary( srcs = ["channelz_sampler.cc"], external_deps = [ "absl/flags:flag", + "absl/strings", ], language = "c++", tags = [ diff --git a/test/cpp/util/channelz_sampler_test.cc b/test/cpp/util/channelz_sampler_test.cc index eb4e7442614..dd23c9899fa 100644 --- a/test/cpp/util/channelz_sampler_test.cc +++ b/test/cpp/util/channelz_sampler_test.cc @@ -26,6 +26,7 @@ #include #include +#include "absl/strings/str_cat.h" #include "gtest/gtest.h" #include @@ -44,6 +45,7 @@ #include "src/core/lib/gpr/env.h" #include "src/cpp/server/channelz/channelz_service.h" #include "src/proto/grpc/testing/test.grpc.pb.h" +#include "test/core/util/port.h" #include "test/core/util/test_config.h" #include "test/cpp/util/subprocess.h" #include "test/cpp/util/test_credentials_provider.h" @@ -174,6 +176,9 @@ int main(int argc, char** argv) { } else { g_root = "."; } + + /// ensures the target address is unique even if this test is run in parallel + server_address = absl::StrCat("0.0.0.0:", grpc_pick_unused_port_or_die()); int ret = RUN_ALL_TESTS(); return ret; }