From e4829b9306c1a643317b46412d2a77fbf385d4f4 Mon Sep 17 00:00:00 2001 From: "Victory, Eagle" Date: Wed, 3 Jun 2026 14:39:09 +0200 Subject: [PATCH] test(plugins/cgroups): Invert how the manual integration tests work in cgroup plugins --- .circleci/config.yml | 2 +- plugins/cgroups/k8s/tests/k8s.rs | 6 ++-- plugins/cgroups/oar/tests/oar.rs | 12 ++++---- plugins/cgroups/raw/tests/raw.rs | 6 ++-- .../util-cgroups-plugins/tests/tests.rs | 30 +++++++++---------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f9623fd19..267861b74 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -58,7 +58,7 @@ jobs: no_output_timeout: 30s environment: # tests that manipulate the cgroupfs don't work in the CI container, because it has no systemd user slice, so the tests cannot create cgroups - SKIP_CGROUPFS_TESTS: true + RUN_CGROUPFS_TESTS: false # Caching "target" is not worth it because it is costly to extract the huge cache. # So, we only cache some cargo data. diff --git a/plugins/cgroups/k8s/tests/k8s.rs b/plugins/cgroups/k8s/tests/k8s.rs index b81c2dfbd..8053e806d 100644 --- a/plugins/cgroups/k8s/tests/k8s.rs +++ b/plugins/cgroups/k8s/tests/k8s.rs @@ -25,10 +25,10 @@ const TOKEN_CONTENT: &str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMj #[test] fn test_k8s_cgroupv2() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let _ = env_logger::Builder::from_default_env().try_init(); diff --git a/plugins/cgroups/oar/tests/oar.rs b/plugins/cgroups/oar/tests/oar.rs index 4fc529eaa..ef45352f1 100644 --- a/plugins/cgroups/oar/tests/oar.rs +++ b/plugins/cgroups/oar/tests/oar.rs @@ -22,10 +22,10 @@ const TOLERANCE: Duration = Duration::from_millis(500); #[test] #[serial] fn test_oar3() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let _ = env_logger::Builder::from_default_env().try_init(); @@ -107,10 +107,10 @@ fn test_oar3() -> anyhow::Result<()> { #[test] #[serial] fn test_oar2() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let _ = env_logger::Builder::from_default_env().try_init(); diff --git a/plugins/cgroups/raw/tests/raw.rs b/plugins/cgroups/raw/tests/raw.rs index fa87a63a1..95fc368ed 100644 --- a/plugins/cgroups/raw/tests/raw.rs +++ b/plugins/cgroups/raw/tests/raw.rs @@ -21,10 +21,10 @@ const TOLERANCE: Duration = Duration::from_millis(500); #[test] fn test_raw_cgroupv2() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let _ = env_logger::Builder::from_default_env().try_init(); diff --git a/plugins/cgroups/util-cgroups-plugins/tests/tests.rs b/plugins/cgroups/util-cgroups-plugins/tests/tests.rs index 2f1ce4c13..c5e5bba9f 100644 --- a/plugins/cgroups/util-cgroups-plugins/tests/tests.rs +++ b/plugins/cgroups/util-cgroups-plugins/tests/tests.rs @@ -159,10 +159,10 @@ impl AlumetPlugin for DumbOARPlugin2 { #[test] fn test_correct_transform() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let app_slice = find_user_app_slice(Path::new(SYSFS_CGROUP))?; @@ -228,10 +228,10 @@ fn test_correct_transform() -> anyhow::Result<()> { #[test] fn test_cgroups_files_not_created() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; let app_slice = find_user_app_slice(Path::new(SYSFS_CGROUP)).unwrap(); @@ -294,10 +294,11 @@ fn test_cgroups_files_not_created() -> anyhow::Result<()> { #[test] fn test_cgroup_v2_hierarchy_not_created() -> anyhow::Result<()> { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return Ok(()); - } + }; + let app_slice = find_user_app_slice(Path::new(SYSFS_CGROUP)).unwrap(); // Create cgroupv2 hierarchy @@ -409,11 +410,12 @@ fn test_no_cgroupv2_at_all() -> anyhow::Result<()> { } #[test] -fn test_on_cgroupfs_mounted() -> () { - if std::env::var_os("SKIP_CGROUPFS_TESTS").is_some() { - println!("skipped because SKIP_CGROUPFS_TESTS is set"); +fn test_on_cgroupfs_mounted() { + let Ok("true" | "yes" | "1") = std::env::var("RUN_CGROUPFS_TESTS").as_deref() else { + println!("skipped because RUN_CGROUPFS_TESTS is not set"); return (); - } + }; + let app_slice = find_user_app_slice(Path::new(SYSFS_CGROUP)).unwrap(); // Create cgroupv2 hierarchy let cgroup_dir_parent = tempfile::tempdir_in(&app_slice) @@ -432,8 +434,6 @@ fn test_on_cgroupfs_mounted() -> () { )]; let ret = shared_hierarchy.on_cgroupfs_mounted(&cgroup_hierarchy); assert!(ret.is_ok()); - - () } fn prepare_mock_measurements(ctx: &mut TransformCheckInputContext, path: PathBuf) -> anyhow::Result {