use rrkernel::scheduler;
#[test]
fn blocking_with_no_current_task_is_counted_and_loud_in_debug() {
let before = scheduler::blocks_without_current();
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(|_| {}));
let result = std::panic::catch_unwind(|| scheduler::sleep_ticks(1));
std::panic::set_hook(prev);
let after = scheduler::blocks_without_current();
assert!(
after > before,
"a wait that cannot happen must still be counted (it is the release-build signal)"
);
if cfg!(debug_assertions) {
assert!(
result.is_err(),
"debug builds must assert rather than silently not waiting: this is the bug"
);
}
}
#[test]
fn blocking_with_no_current_task_does_not_touch_any_task_state() {
let t0 = scheduler::tick_count();
let a0 = scheduler::active_threads();
let c0 = scheduler::blocks_without_current();
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(|_| {}));
let _ = std::panic::catch_unwind(|| {
let _ = scheduler::block_until_tick(0, 0);
});
std::panic::set_hook(prev);
assert_eq!(scheduler::active_threads(), a0);
assert_eq!(scheduler::tick_count(), t0);
assert!(
scheduler::blocks_without_current() > c0,
"the failed unbounded wait must be counted too"
);
}