From b41652aa8ac0b7c66c6ab79255e77484c2c29e1b Mon Sep 17 00:00:00 2001 From: Fred Douglas Date: Tue, 28 May 2019 11:30:24 -0400 Subject: [PATCH] fix flake in ads_integration_test Signed-off-by: Fred Douglas --- test/integration/server.cc | 39 ++++++++++++++++++++------------------ test/integration/server.h | 3 +++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/test/integration/server.cc b/test/integration/server.cc index 4224cb36a23f3..9f314549906b2 100644 --- a/test/integration/server.cc +++ b/test/integration/server.cc @@ -169,24 +169,26 @@ void IntegrationTestServerImpl::createAndRunEnvoyServer( Network::Address::InstanceConstSharedPtr local_address, ListenerHooks& hooks, Thread::BasicLockable& access_log_lock, Server::ComponentFactory& component_factory, Runtime::RandomGeneratorPtr&& random_generator) { - Stats::FakeSymbolTableImpl symbol_table; - Server::HotRestartNopImpl restarter; - ThreadLocal::InstanceImpl tls; - Stats::HeapStatDataAllocator stats_allocator(symbol_table); - Stats::ThreadLocalStoreImpl stat_store(stats_allocator); - - Server::InstanceImpl server(options, time_system, local_address, hooks, restarter, stat_store, - access_log_lock, component_factory, std::move(random_generator), tls, - Thread::threadFactoryForTest(), Filesystem::fileSystemForTest(), - nullptr); - // This is technically thread unsafe (assigning to a shared_ptr accessed - // across threads), but because we synchronize below through serverReady(), the only - // consumer on the main test thread in ~IntegrationTestServerImpl will not race. - admin_address_ = server.admin().socket().localAddress(); - server_ = &server; - stat_store_ = &stat_store; - serverReady(); - server.run(); + { + Stats::FakeSymbolTableImpl symbol_table; + Server::HotRestartNopImpl restarter; + ThreadLocal::InstanceImpl tls; + Stats::HeapStatDataAllocator stats_allocator(symbol_table); + Stats::ThreadLocalStoreImpl stat_store(stats_allocator); + Server::InstanceImpl server(options, time_system, local_address, hooks, restarter, stat_store, + access_log_lock, component_factory, std::move(random_generator), + tls, Thread::threadFactoryForTest(), + Filesystem::fileSystemForTest(), nullptr); + // This is technically thread unsafe (assigning to a shared_ptr accessed + // across threads), but because we synchronize below through serverReady(), the only + // consumer on the main test thread in ~IntegrationTestServerImpl will not race. + admin_address_ = server.admin().socket().localAddress(); + server_ = &server; + stat_store_ = &stat_store; + serverReady(); + server.run(); + } + server_gone_.Notify(); } IntegrationTestServerImpl::~IntegrationTestServerImpl() { @@ -202,6 +204,7 @@ IntegrationTestServerImpl::~IntegrationTestServerImpl() { admin_address, "POST", "/quitquitquit", "", Http::CodecClient::Type::HTTP1); EXPECT_TRUE(response->complete()); EXPECT_EQ("200", response->headers().Status()->value().getStringView()); + server_gone_.WaitForNotification(); } } diff --git a/test/integration/server.h b/test/integration/server.h index a0dca125f8751..6024db40e0d44 100644 --- a/test/integration/server.h +++ b/test/integration/server.h @@ -23,6 +23,8 @@ #include "test/test_common/test_time_system.h" #include "test/test_common/utility.h" +#include "absl/synchronization/notification.h" + namespace Envoy { namespace Server { @@ -380,6 +382,7 @@ class IntegrationTestServerImpl : public IntegrationTestServer { Server::Instance* server_{}; Stats::Store* stat_store_{}; Network::Address::InstanceConstSharedPtr admin_address_; + absl::Notification server_gone_; }; } // namespace Envoy