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
This commit is contained in:
Fabricio Voznika
2021-03-08 17:01:30 -08:00
committed by gVisor bot
parent 8018bf62ba
commit 3c4485966c
+13 -10
View File
@@ -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;