From 74543b77c600dde0b31102d288cc09d8960b6563 Mon Sep 17 00:00:00 2001 From: Markus Handell Date: Mon, 28 Jun 2021 10:29:15 +0200 Subject: [PATCH] PlatformThreadTest: fix flake. This change aims to fix a flake that could have been caused by threads lingering past the main thread lifetime. Bug: webrtc:12913 Change-Id: I144078b41d59f46398212f48cdd4b0cf3f204bfe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/224080 Reviewed-by: Markus Handell Reviewed-by: Mirko Bonadei Commit-Queue: Markus Handell Cr-Commit-Position: refs/heads/master@{#34371} --- rtc_base/platform_thread_unittest.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rtc_base/platform_thread_unittest.cc b/rtc_base/platform_thread_unittest.cc index 0da822cf85..b60d2131b7 100644 --- a/rtc_base/platform_thread_unittest.cc +++ b/rtc_base/platform_thread_unittest.cc @@ -29,10 +29,12 @@ TEST(PlatformThreadTest, StartFinalize) { EXPECT_FALSE(thread.empty()); thread.Finalize(); EXPECT_TRUE(thread.empty()); - thread = PlatformThread::SpawnDetached([] {}, "2"); + rtc::Event done; + thread = PlatformThread::SpawnDetached([&] { done.Set(); }, "2"); EXPECT_FALSE(thread.empty()); thread.Finalize(); EXPECT_TRUE(thread.empty()); + done.Wait(30000); } TEST(PlatformThreadTest, MovesEmpty) { @@ -47,10 +49,12 @@ TEST(PlatformThreadTest, MovesHandles) { PlatformThread thread2 = std::move(thread1); EXPECT_TRUE(thread1.empty()); EXPECT_FALSE(thread2.empty()); - thread1 = PlatformThread::SpawnDetached([] {}, "2"); + rtc::Event done; + thread1 = PlatformThread::SpawnDetached([&] { done.Set(); }, "2"); thread2 = std::move(thread1); EXPECT_TRUE(thread1.empty()); EXPECT_FALSE(thread2.empty()); + done.Wait(30000); } TEST(PlatformThreadTest,