mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-19 11:06:17 +00:00
test: assert four leaf-crate smoke tests, and two more census fixes
Two more census heuristics, both verified by bisecting the candidate count so a "fix" that widened the queue could not slip through:
- any `assert*!` macro counts as verification, not just the three built-ins — `assert_fields_bound!` in `protos` was being missed. The pattern deliberately stays a substring match: an earlier attempt anchored it with `\b`, which silently stopped matching prefixed macros like `const_assert!` and pushed the queue from 32 to 55 before the count caught it.
- `let _ = Type::<T>::method;` is a signature guard, the same as the already-recognised nested-fn form. That is `iam`'s deprecated-API test.
Tree-wide candidates go 32 to 30 from the script alone, then to 26 with the four tests below.
`detect_storage_media`'s two tests only checked that the call did not panic, over a `match` whose arms were all empty. What the machine reports depends on the machine, but two rules do not: an override wins over probing, including when probing is disabled, and disabled probing reports `Unknown` rather than guessing. A third test keeps the platform call and asserts it returns a known variant *and* the same one twice — a probe that flapped would make the scheduler's profile depend on when it asked.
`runtime_facade_stops_empty_replay_workers` called the stop path and asserted nothing. It now checks the worker list is empty afterwards and that a second call stays harmless, which is what shutdown paths actually do.
`test_mask_never_recurses_for_any_variant` discarded every mask. Termination is still the property under test — a regression overflows the stack rather than failing an assertion — but the masks are now collected and checked, so the loop cannot fold away and a variant that starts returning an empty mask is caught too.
Two known false positives are left in the queue rather than chased: `utils/src/string.rs:942` does assert, but its input string `"{1...2}}"` unbalances the scanner's brace counter and truncates the body before the assertion. Making the counter literal-aware needs a lexer that understands raw strings — a first attempt desynchronised on `r#"{"invalid": json}"#` and pushed the queue to 120, so it was backed out. `s3select-api:379` declares a nested exhaustive-match fn and never calls it; recognising that shape without hiding genuinely empty bodies needs more care than it is worth today.
Refs backlog#1836
This commit is contained in:
@@ -436,30 +436,45 @@ mod tests {
|
||||
assert_eq!(unknown_profile.sequential_boost_multiplier, 1.0);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
// What platform probing returns depends on the machine, so these pin the two
|
||||
// rules that do not: the override wins over probing, and probing that is
|
||||
// switched off reports Unknown rather than guessing (rustfs/backlog#1836).
|
||||
#[test]
|
||||
fn test_linux_storage_detection_exists() {
|
||||
// This test just verifies the detection function exists and doesn't panic
|
||||
// The actual result depends on the system it's running on
|
||||
let result = detect_storage_media(true, "");
|
||||
// We should get some result (not panic)
|
||||
match result {
|
||||
StorageMedia::Nvme | StorageMedia::Ssd | StorageMedia::Hdd | StorageMedia::Unknown => {
|
||||
// All valid results
|
||||
}
|
||||
fn storage_media_override_wins_over_platform_detection() {
|
||||
for (override_value, expected) in [
|
||||
("nvme", StorageMedia::Nvme),
|
||||
("ssd", StorageMedia::Ssd),
|
||||
("hdd", StorageMedia::Hdd),
|
||||
] {
|
||||
assert_eq!(detect_storage_media(true, override_value), expected);
|
||||
assert_eq!(
|
||||
detect_storage_media(false, override_value),
|
||||
expected,
|
||||
"an override must be honoured even with detection disabled"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn test_macos_storage_detection_exists() {
|
||||
// This test just verifies the detection function exists and doesn't panic
|
||||
let result = detect_storage_media(true, "");
|
||||
// We should get some result (not panic)
|
||||
match result {
|
||||
StorageMedia::Nvme | StorageMedia::Ssd | StorageMedia::Hdd | StorageMedia::Unknown => {
|
||||
// All valid results
|
||||
}
|
||||
}
|
||||
fn disabled_detection_reports_unknown_instead_of_guessing() {
|
||||
assert_eq!(detect_storage_media(false, ""), StorageMedia::Unknown);
|
||||
assert_eq!(
|
||||
detect_storage_media(false, "not-a-medium"),
|
||||
StorageMedia::Unknown,
|
||||
"an unparseable override falls through to the disabled path"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabled_detection_returns_a_medium_for_this_platform() {
|
||||
// Whatever this machine reports, it must be one of the known variants and
|
||||
// it must be stable across calls — a probe that flapped would make the
|
||||
// scheduler's profile depend on when it asked.
|
||||
let first = detect_storage_media(true, "");
|
||||
assert!(matches!(
|
||||
first,
|
||||
StorageMedia::Nvme | StorageMedia::Ssd | StorageMedia::Hdd | StorageMedia::Unknown
|
||||
));
|
||||
assert_eq!(detect_storage_media(true, ""), first);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,9 +527,19 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn runtime_facade_stops_empty_replay_workers() {
|
||||
async fn stopping_replay_workers_is_a_no_op_when_there_are_none() {
|
||||
let (facade, _, _) = build_facade();
|
||||
|
||||
facade.stop_replay_workers().await;
|
||||
|
||||
// The stop path takes the worker list and hands it to the adapter, so an
|
||||
// empty facade must come back with the list still empty and dispatch
|
||||
// released rather than left paused (rustfs/backlog#1836).
|
||||
assert!(facade.replay_workers.read().await.is_empty());
|
||||
|
||||
// Calling it twice must stay harmless: shutdown paths do exactly that.
|
||||
facade.stop_replay_workers().await;
|
||||
assert!(facade.replay_workers.read().await.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -873,9 +873,16 @@ mod tests {
|
||||
/// now return a finite, non-panicking mask.
|
||||
#[test]
|
||||
fn test_mask_never_recurses_for_any_variant() {
|
||||
for ev in ALL_EVENT_NAMES {
|
||||
// Must terminate (no infinite recursion / stack overflow).
|
||||
let _ = ev.mask();
|
||||
// Terminating is the point — a regression here overflows the stack rather
|
||||
// than failing an assertion — but the masks are collected and checked so
|
||||
// the loop cannot be optimised into nothing and so a variant that starts
|
||||
// returning an empty mask is caught too (rustfs/backlog#1836).
|
||||
let masks: Vec<u64> = ALL_EVENT_NAMES.iter().map(|ev| ev.mask()).collect();
|
||||
|
||||
assert_eq!(masks.len(), ALL_EVENT_NAMES.len());
|
||||
for (ev, mask) in ALL_EVENT_NAMES.iter().zip(&masks) {
|
||||
assert_ne!(*mask, 0, "{ev:?} must carry at least one bit");
|
||||
assert_eq!(ev.mask(), *mask, "{ev:?} must return the same mask every call");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user