From 7548e61d44170565c678e9864ed94eefdb6f41e9 Mon Sep 17 00:00:00 2001 From: Jose Ulises Nino Rivera Date: Fri, 9 Apr 2021 12:33:37 -0500 Subject: [PATCH] tsan: fix failure in main_interface_test (#1364) Signed-off-by: Jose Nino Signed-off-by: JP Simard --- mobile/test/common/main_interface_test.cc | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mobile/test/common/main_interface_test.cc b/mobile/test/common/main_interface_test.cc index 82ed536bdd0b..437c72f3ff84 100644 --- a/mobile/test/common/main_interface_test.cc +++ b/mobile/test/common/main_interface_test.cc @@ -15,6 +15,7 @@ namespace Envoy { typedef struct { absl::Notification on_engine_running; absl::Notification on_exit; + absl::Notification on_log; } engine_test_context; // This config is the minimal envoy mobile config that allows for running the engine. @@ -392,31 +393,30 @@ TEST(EngineTest, RecordHistogramValue) { TEST(EngineTest, Logger) { engine_test_context test_context{}; envoy_engine_callbacks engine_cbs{[](void* context) -> void { - auto* engine_running = + auto* test_context = static_cast(context); - engine_running->on_engine_running.Notify(); + test_context->on_engine_running.Notify(); } /*on_engine_running*/, [](void* context) -> void { - auto* exit = static_cast(context); - exit->on_exit.Notify(); + auto* test_context = + static_cast(context); + test_context->on_exit.Notify(); } /*on_exit*/, &test_context /*context*/}; - std::string actual_log; envoy_logger logger{[](envoy_data data, void* context) -> void { - auto* actual_log = static_cast(context); - *actual_log = Data::Utility::copyToString(data); + auto* test_context = static_cast(context); data.release(data.context); + if (!test_context->on_log.HasBeenNotified()) { + test_context->on_log.Notify(); + } }, - &actual_log}; + &test_context}; run_engine(0, engine_cbs, logger, MINIMAL_NOOP_CONFIG.c_str(), LEVEL_DEBUG.c_str()); ASSERT_TRUE(test_context.on_engine_running.WaitForNotificationWithTimeout(absl::Seconds(3))); - std::string expected_log = "logging!"; - ENVOY_LOG_MISC(error, expected_log); - - EXPECT_THAT(actual_log, HasSubstr(expected_log)); + ASSERT_TRUE(test_context.on_log.WaitForNotificationWithTimeout(absl::Seconds(3))); terminate_engine(0); ASSERT_TRUE(test_context.on_exit.WaitForNotificationWithTimeout(absl::Seconds(3)));