From 3c4485966c170850bb677efc88de4c0ecaac1358 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Mon, 8 Mar 2021 16:55:22 -0800 Subject: Fix proc test flakiness Thread from earlier test can show up in `/proc/self/tasks` while the thread tears down. Account for that when searching for procs for the first time in the test. PiperOrigin-RevId: 361689673 --- test/syscalls/linux/proc.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/syscalls/linux/proc.cc b/test/syscalls/linux/proc.cc index e508ce27f..61a421788 100644 --- a/test/syscalls/linux/proc.cc +++ b/test/syscalls/linux/proc.cc @@ -2162,7 +2162,13 @@ class BlockingChild { return tid_; } - void Join() { Stop(); } + void Join() { + { + absl::MutexLock ml(&mu_); + stop_ = true; + } + thread_.Join(); + } private: void Start() { @@ -2172,11 +2178,6 @@ class BlockingChild { mu_.Await(absl::Condition(&stop_)); } - void Stop() { - absl::MutexLock ml(&mu_); - stop_ = true; - } - mutable absl::Mutex mu_; bool stop_ ABSL_GUARDED_BY(mu_) = false; pid_t tid_; @@ -2190,16 +2191,18 @@ class BlockingChild { TEST(ProcTask, NewThreadAppears) { auto initial = ASSERT_NO_ERRNO_AND_VALUE(ListDir("/proc/self/task", false)); BlockingChild child1; - EXPECT_NO_ERRNO(DirContainsExactly("/proc/self/task", - TaskFiles(initial, {child1.Tid()}))); + // Use Eventually* in case a proc from ealier test is still tearing down. + EXPECT_NO_ERRNO(EventuallyDirContainsExactly( + "/proc/self/task", TaskFiles(initial, {child1.Tid()}))); } TEST(ProcTask, KilledThreadsDisappear) { auto initial = ASSERT_NO_ERRNO_AND_VALUE(ListDir("/proc/self/task/", false)); BlockingChild child1; - EXPECT_NO_ERRNO(DirContainsExactly("/proc/self/task", - TaskFiles(initial, {child1.Tid()}))); + // Use Eventually* in case a proc from ealier test is still tearing down. + EXPECT_NO_ERRNO(EventuallyDirContainsExactly( + "/proc/self/task", TaskFiles(initial, {child1.Tid()}))); // Stat child1's task file. Regression test for b/32097707. struct stat statbuf; -- cgit v1.2.3