diff --git a/test/syscalls/linux/cgroup.cc b/test/syscalls/linux/cgroup.cc index a53c9895d..421df540e 100644 --- a/test/syscalls/linux/cgroup.cc +++ b/test/syscalls/linux/cgroup.cc @@ -1214,7 +1214,8 @@ TEST(PIDsCgroup, LimitEnforced) { IsPosixErrorOkAndHolds(baseline + 1)); // Exit the first thread and try create a thread again, which should succeed. - t1.Join(); + ASSERT_NO_ERRNO(child.PollControlFileForChangeAfter( + "pids.current", absl::Seconds(30), [&t1]() { t1.Join(); })); ASSERT_THAT(child.ReadIntegerControlFile("pids.current"), IsPosixErrorOkAndHolds(baseline)); NoopThreads t2(1); diff --git a/test/util/cgroup_util.cc b/test/util/cgroup_util.cc index 4e687481f..dca02c6ce 100644 --- a/test/util/cgroup_util.cc +++ b/test/util/cgroup_util.cc @@ -87,6 +87,12 @@ PosixErrorOr> Cgroup::Tasks() const { PosixError Cgroup::PollControlFileForChange(absl::string_view name, absl::Duration timeout) const { + return PollControlFileForChangeAfter(name, timeout, []() {}); +} + +PosixError Cgroup::PollControlFileForChangeAfter( + absl::string_view name, absl::Duration timeout, + std::function body) const { const absl::Duration poll_interval = absl::Milliseconds(10); const absl::Time deadline = absl::Now() + timeout; const std::string alias_path = absl::StrFormat("[cg#%d]/%s", id_, name); @@ -94,6 +100,8 @@ PosixError Cgroup::PollControlFileForChange(absl::string_view name, ASSIGN_OR_RETURN_ERRNO(const int64_t initial_value, ReadIntegerControlFile(name)); + body(); + while (true) { ASSIGN_OR_RETURN_ERRNO(const int64_t current_value, ReadIntegerControlFile(name)); diff --git a/test/util/cgroup_util.h b/test/util/cgroup_util.h index f45945b3e..a13f1772d 100644 --- a/test/util/cgroup_util.h +++ b/test/util/cgroup_util.h @@ -78,6 +78,11 @@ class Cgroup { PosixError PollControlFileForChange(absl::string_view name, absl::Duration timeout) const; + // Waits for a control file's value to change after calling body. + PosixError PollControlFileForChangeAfter(absl::string_view name, + absl::Duration timeout, + std::function body) const; + // Returns the thread ids of the leaders of thread groups managed by this // cgroup. PosixErrorOr> Procs() const;