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 <handellm@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34371}
diff --git a/rtc_base/platform_thread_unittest.cc b/rtc_base/platform_thread_unittest.cc
index 0da822c..b60d213 100644
--- a/rtc_base/platform_thread_unittest.cc
+++ b/rtc_base/platform_thread_unittest.cc
@@ -29,10 +29,12 @@
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 @@
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,