summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/proc.cc
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2021-03-08 16:55:22 -0800
committergVisor bot <gvisor-bot@google.com>2021-03-08 17:01:30 -0800
commit3c4485966c170850bb677efc88de4c0ecaac1358 (patch)
tree1cf33dbbc164ac3b758f8b7a035583547b5446e1 /test/syscalls/linux/proc.cc
parent8018bf62ba5db591ad179ef6a2236bd6179fc4d6 (diff)
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
Diffstat (limited to 'test/syscalls/linux/proc.cc')
-rw-r--r--test/syscalls/linux/proc.cc23
1 files 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;