Skip to content

Demote functional tests that do not require the VM - #776

Open
bfjelds (bfjelds) wants to merge 2 commits into
mainfrom
user/bfjelds/demote-non-functional-tests
Open

Demote functional tests that do not require the VM#776
bfjelds (bfjelds) wants to merge 2 commits into
mainfrom
user/bfjelds/demote-non-functional-tests

Conversation

@bfjelds

Copy link
Copy Markdown
Member

Converts 38 #[functional_test] tests to plain #[test]s. These tests only touch synthetic temp-root state, or invoke tools/paths already available in the plain unit-test image, with no real disk/EFI mutation, privileged mount, or VM-specific hardware/layout dependency.

9 tests initially identified as candidates were reverted after real test runs proved they need root/privileged mount, VM-specific hardware, or a tool (systemd-firstboot) absent from the plain unit-test image:

  • logging::tracestream::test_populate_platform_info (hardcodes VM CPU/RAM specs)
  • subsystems::extensions::mod tests x4 (loop-mount setup needs root)
  • osutils::container tests x3 (writes to real root-level paths, needs root)
  • subsystems::storage::verity::test_create_machine_id (needs systemd-firstboot, absent from base image)

Verified: cargo check --all-targets --workspace --all-features clean; full unit-test suites pass with zero failures (trident 396/396, osutils 167/167, osmodifier 101/101).

@bfjelds

Copy link
Copy Markdown
Member Author

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

…it tests

Converts tests that only require synthetic/temp-root state, or invoke
tools/paths already available in the plain unit-test image, to plain
#[test]s, with no real disk/EFI mutation, privileged mount, or
VM-specific hardware/layout dependency.

11 tests initially attempted were reverted after real CI/local test
runs proved they need root/privileged mount, VM-specific hardware, a
tool absent from the plain unit-test image, or query the real
system's block-device layout:
- logging::tracestream::test_populate_platform_info (hardcodes VM CPU/RAM specs)
- subsystems::extensions::mod tests x4 (loop-mount setup needs root)
- osutils::container tests x3 (writes to real root-level paths, needs root)
- subsystems::storage::verity::test_create_machine_id (needs systemd-firstboot, absent from base image)
- engine::rollback::test_construct_by_partuuid_path (resolves PARTUUID via real device lookup)
- stream::test_get_candidates (asserts against the real block-device layout)

Verified: cargo check --all-targets --workspace --all-features clean;
full workspace unit-test suite passes with zero failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bfjelds
bfjelds (bfjelds) force-pushed the user/bfjelds/demote-non-functional-tests branch from 314ada8 to 072599e Compare September 4, 2026 14:52
@bfjelds

Copy link
Copy Markdown
Member Author

Fixed: est_construct_by_partuuid_path and est_get_candidates both assert against real block-device layout (via lsblk/�lkid), not pure logic as originally assessed. Reverted to #[functional_test]. Also confirmed the other 36 demoted tests all passed cleanly in the same CI run alongside the 2 failures. Full workspace cargo test now passes with zero failures.

@bfjelds

Copy link
Copy Markdown
Member Author

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@bfjelds

Copy link
Copy Markdown
Member Author

/azp run [GITHUB]-trident-pr-e2e

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@bfjelds
bfjelds (bfjelds) marked this pull request as ready for review September 4, 2026 16:19
@bfjelds
bfjelds (bfjelds) requested a review from a team as a code owner September 4, 2026 16:19
Copilot AI lite review requested due to automatic review settings September 4, 2026 16:19
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated monitor_metrics unit test module no longer imports Arc despite using it, which will fail compilation, and a couple of new lsblk unit tests assert on highly environment/version-sensitive command output.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR reduces reliance on the functional-test harness by demoting a set of functional tests that only require synthetic filesystem state and common tools into regular Rust unit tests, keeping VM/privilege-dependent tests under #[cfg(feature = "functional-test")].

Changes:

  • Converted multiple #[functional_test] cases to #[test] and moved them under #[cfg(test)] mod tests where appropriate.
  • Introduced/relocated a few unit-only negative/validation tests while leaving privileged/VM-dependent coverage in functional_test modules.
  • Refactored some test helpers/imports to support the new unit-test layout.
File summaries
File Description
crates/trident/src/monitor_metrics.rs Converts a functional tracing/metrics test to a unit test module.
crates/trident/src/logging/tracestream.rs Moves populate_additional_fields coverage into unit tests (keeps VM-specific platform test functional).
crates/trident/src/engine/storage/rebuild.rs Adds unit tests for validate_rebuild_raid error paths and updates config imports.
crates/trident/src/engine/rollback.rs Demotes a device-path comparison functional test to a unit test; keeps other functional tests gated.
crates/trident/src/datastore.rs Demotes a datastore open/persist/reopen functional test to a unit test.
crates/osutils/src/udevadm.rs Demotes udevadm settle test into unit tests; leaves trigger/wait functional.
crates/osutils/src/lsblk.rs Demotes negative lsblk error-path tests into unit tests.
crates/osutils/src/chroot.rs Demotes a negative chroot-entry test into unit tests.
crates/osutils/src/block_devices.rs Demotes a partx_update failure-path test into unit tests.
crates/osutils/src/blkid.rs Splits blkid tests between functional (device-backed success paths) and unit (failure paths).
crates/osmodifier/src/services.rs Demotes service enable/disable tests to unit tests using a synthetic systemd tree.
crates/osmodifier/src/selinux.rs Demotes SELinux config/GRUB update tests to unit tests using a temp root.
crates/osmodifier/src/modules.rs Demotes module configuration tests to unit tests with temp-root filesystem state.
crates/osmodifier/src/lib.rs Demotes integration-style modify_os tests to unit tests; keeps context path tests co-located.
crates/osmodifier/src/hostname.rs Demotes hostname update tests to unit tests using a temp root.
Review details

Suppressed comments (1)

crates/osutils/src/lsblk.rs:1298

  • This assertion is extremely brittle because it depends on the exact pretty-printed JSON and stderr formatting from lsblk, which can vary across util-linux versions and environments. Prefer asserting only on stable substrings (e.g. the "not a block device" stderr) or on structured error kinds if available.
    #[test]
    fn test_get_fail_on_missing_file() {
        assert!(super::get(Path::new("/dev/does-not-exist")).unwrap_err().root_cause().to_string().contains("stdout:\n{\n   \"blockdevices\": [\n\n   ]\n}\n\n\nstderr:\nlsblk: /dev/does-not-exist: not a block device\n\n"));
    }
  • Files reviewed: 15/15 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/trident/src/monitor_metrics.rs
Comment thread crates/osutils/src/lsblk.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants