This is an automated email from the ASF dual-hosted git repository.
bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 4dd304472 [cgroups2] Test fixture to cleanup `TEST_CGROUP`.
4dd304472 is described below
commit 4dd30447257bf2375620be04dcb4fdfd3ff09d37
Author: Devin Leamy <[email protected]>
AuthorDate: Wed Mar 20 12:30:43 2024 -0400
[cgroups2] Test fixture to cleanup `TEST_CGROUP`.
Many cgroups tests require creating a child cgroup and then updating control
files within that cgroup. To avoid requiring test writers to manually
cleanup
and conditionally create `TEST_CGROUP`, we add cleanup logic to the setup
and
teardown of the `Cgroups2Test` test fixture.
This closes #528
---
src/tests/containerizer/cgroups2_tests.cpp | 37 ++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/tests/containerizer/cgroups2_tests.cpp
b/src/tests/containerizer/cgroups2_tests.cpp
index 2c95eb023..795dc8816 100644
--- a/src/tests/containerizer/cgroups2_tests.cpp
+++ b/src/tests/containerizer/cgroups2_tests.cpp
@@ -33,7 +33,33 @@ namespace mesos {
namespace internal {
namespace tests {
-class Cgroups2Test : public TemporaryDirectoryTest {};
+const string TEST_CGROUP = "test";
+
+// Cgroups2 test fixture that ensures `TEST_CGROUP` does not
+// exist before and after the test is run.
+class Cgroups2Test : public TemporaryDirectoryTest
+{
+protected:
+ void SetUp()
+ {
+ TemporaryDirectoryTest::SetUp();
+
+ // Cleanup the test cgroup, in case a previous test run didn't clean it
+ // up properly.
+ if (cgroups2::exists(TEST_CGROUP)) {
+ ASSERT_SOME(cgroups2::destroy(TEST_CGROUP));
+ }
+ }
+
+ void TearDown()
+ {
+ if (cgroups2::exists(TEST_CGROUP)) {
+ ASSERT_SOME(cgroups2::destroy(TEST_CGROUP));
+ }
+
+ TemporaryDirectoryTest::TearDown();
+ }
+};
TEST_F(Cgroups2Test, ROOT_CGROUPS2_Enabled)
@@ -66,8 +92,7 @@ TEST_F(Cgroups2Test, ROOT_CGROUPS2_AvailableSubsystems)
TEST_F(Cgroups2Test, ROOT_CGROUPS2_AssignProcessToCgroup)
{
- string cgroup = "test";
- ASSERT_SOME(cgroups2::create(cgroup));
+ ASSERT_SOME(cgroups2::create(TEST_CGROUP));
pid_t pid = ::fork();
ASSERT_NE(-1, pid);
@@ -82,14 +107,12 @@ TEST_F(Cgroups2Test, ROOT_CGROUPS2_AssignProcessToCgroup)
// Add the forked child to the cgroup and check that its 'cgroup' membership
// is correct.
- EXPECT_SOME(cgroups2::move_process(cgroup, pid));
- EXPECT_SOME_EQ(cgroup, cgroups2::cgroup(pid));
+ EXPECT_SOME(cgroups2::move_process(TEST_CGROUP, pid));
+ EXPECT_SOME_EQ(TEST_CGROUP, cgroups2::cgroup(pid));
// Kill the child process.
ASSERT_NE(-1, ::kill(pid, SIGKILL));
AWAIT_EXPECT_WTERMSIG_EQ(SIGKILL, process::reap(pid));
-
- EXPECT_SOME(cgroups2::destroy(cgroup));
}
} // namespace tests {