diff --git a/crates/io-core/src/io_profile.rs b/crates/io-core/src/io_profile.rs index 86cd79448..46b894c49 100644 --- a/crates/io-core/src/io_profile.rs +++ b/crates/io-core/src/io_profile.rs @@ -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); } } diff --git a/crates/notify/src/runtime_facade.rs b/crates/notify/src/runtime_facade.rs index 683a01ba6..f692880c5 100644 --- a/crates/notify/src/runtime_facade.rs +++ b/crates/notify/src/runtime_facade.rs @@ -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] diff --git a/crates/s3-types/src/event_name.rs b/crates/s3-types/src/event_name.rs index 659b88b46..dee252dbd 100644 --- a/crates/s3-types/src/event_name.rs +++ b/crates/s3-types/src/event_name.rs @@ -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 = 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"); } } diff --git a/scripts/find_assertless_tests.py b/scripts/find_assertless_tests.py index 5b9f8ac9a..094d051af 100755 --- a/scripts/find_assertless_tests.py +++ b/scripts/find_assertless_tests.py @@ -49,7 +49,7 @@ import sys from pathlib import Path VERIFY_SIGNALS = re.compile( - r"assert!|assert_eq!|assert_ne!|debug_assert|panic!\(|\.expect\(|\.unwrap\(|" + r"assert[a-z0-9_]*!|debug_assert|panic!\(|\.expect\(|\.unwrap\(|" r"unreachable!|matches!\(|insta::|proptest!|\.await\?|\)\?|\?;|should_panic" ) DELEGATION = re.compile( @@ -70,12 +70,17 @@ SINGLE_CALL_BODY = re.compile( # system is the assertion, exactly like the `fn _name()` form below. SIGNATURE_GUARD = re.compile(r"\bfn\s+[a-zA-Z0-9_]+\s*(?:<[^>]*>)?\s*\([^;]*\)[^;]*\{", re.S) DISCARDED_BINDING = re.compile(r"\blet\s+_\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*\s*;") +# `let _ = Type::::method;` — a path item referenced but never called can only +# be a signature guard; the call form (`let _ = x.foo();`) is excluded by the +# absence of parens before the semicolon. +DISCARDED_PATH_ITEM = re.compile(r"\blet\s+_\s*=\s*[a-zA-Z_][a-zA-Z0-9_]*(?:::(?:<[^>]*>|[a-zA-Z_][a-zA-Z0-9_]*))+\s*;") COMPILE_TIME_CHECK = re.compile(r"\bfn\s+_[a-zA-Z0-9_]*\s*(?:<[^>]*>)?\s*\(") TEST_ATTR = re.compile(r"#\[(?:tokio::)?test[\](]") TEST_CASE_ATTR = re.compile(r"#\[test_case") FN_LINE = re.compile(r"^\s*(?:pub\s+)?(?:async\s+)?fn\s+([a-zA-Z0-9_]+)") + def extract_body(text: str) -> str: """Return what is between the outermost braces of a scanned function.""" start = text.find("{") @@ -136,6 +141,7 @@ def scan_file(path: Path): DELEGATION.search(text) or SINGLE_CALL_BODY.match(inner) or (SIGNATURE_GUARD.search(inner) and DISCARDED_BINDING.search(inner)) + or DISCARDED_PATH_ITEM.search(inner) ) if not VERIFY_SIGNALS.search(text) and not VERIFY_SIGNALS.search(attr_text) and not delegates and not COMPILE_TIME_CHECK.search(text): print(f"{path}:{j + 1}: {name}")