diff --git a/test/common/event/dispatcher_impl_test.cc b/test/common/event/dispatcher_impl_test.cc index 25185a30364e2..951617feec356 100644 --- a/test/common/event/dispatcher_impl_test.cc +++ b/test/common/event/dispatcher_impl_test.cc @@ -85,6 +85,7 @@ class DispatcherImplTest : public testing::Test { dispatcher_thread_->join(); } + NiceMock scope_; // Used in InitializeStats, must outlive dispatcher_->exit(). Api::ApiPtr api_; Thread::ThreadPtr dispatcher_thread_; DispatcherPtr dispatcher_; @@ -96,11 +97,9 @@ class DispatcherImplTest : public testing::Test { }; TEST_F(DispatcherImplTest, InitializeStats) { - // NiceMock because deliverHistogramToSinks may or may not be called, depending on timing. - NiceMock scope; - EXPECT_CALL(scope, histogram("test.dispatcher.loop_duration_us")); - EXPECT_CALL(scope, histogram("test.dispatcher.poll_delay_us")); - dispatcher_->initializeStats(scope, "test."); + EXPECT_CALL(scope_, histogram("test.dispatcher.loop_duration_us")); + EXPECT_CALL(scope_, histogram("test.dispatcher.poll_delay_us")); + dispatcher_->initializeStats(scope_, "test."); } TEST_F(DispatcherImplTest, Post) {