Skip to content

Commit 234b356

Browse files
committed
Fix the flaky bm_opencensus_plugin
1 parent d86acba commit 234b356

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

test/cpp/microbenchmarks/bm_opencensus_plugin.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "opencensus/stats/stats.h"
2929
#include "src/cpp/ext/filters/census/grpc_plugin.h"
3030
#include "src/proto/grpc/testing/echo.grpc.pb.h"
31+
#include "test/core/util/test_config.h"
3132
#include "test/cpp/microbenchmarks/helpers.h"
3233

3334
using ::grpc::RegisterOpenCensusPlugin;
@@ -86,6 +87,8 @@ class EchoServerThread final {
8687
};
8788

8889
static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
90+
grpc::testing::TestEnvironment env(0, {});
91+
8992
EchoServerThread server;
9093
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =
9194
grpc::testing::EchoTestService::NewStub(grpc::CreateChannel(
@@ -101,11 +104,7 @@ static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
101104
BENCHMARK(BM_E2eLatencyCensusDisabled);
102105

103106
static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
104-
// Avoid a data race between registering plugin and shutdown of previous
105-
// test (order-dependent) by doing an init/shutdown so that any previous
106-
// shutdowns are fully complete first.
107-
grpc_init();
108-
grpc_shutdown_blocking();
107+
grpc::testing::TestEnvironment env(0, {});
109108

110109
// Now start the test by registering the plugin (once in the execution)
111110
RegisterOnce();

0 commit comments

Comments
 (0)