From 404776ac046d5f96d09d9835dc02bc26b293912d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 03:57:54 -0800 Subject: [PATCH] Plug-ins: the failed-stage deferral test no longer depends on CPU load effect::tests::failed_and_missing_stages_are_deferred_with_their_reason installed a plug-in that runs to the default instruction budget (about 51 million instructions for its input) inside a first view, whose budget is 2,000 ms of real time. Under heavy CPU load the run took longer than that, the view's budget cut it short, and the stage was deferred for time instead of as failed, so last_error was empty and the assertion at effect.rs:722 failed. With the test pinned to one core beside 15 busy loops it failed 3 runs of 3 that way. The test now gives the plug-in a budget of 100,000 instructions, so the run ends in an instruction-budget failure long before the view's budget runs out, and it checks that the error is the instruction budget. The same test passes 5 runs of 5 beside 15 busy loops and 5 of 5 beside 100. --- crates/plugins/src/effect.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/plugins/src/effect.rs b/crates/plugins/src/effect.rs index 2107b5f7b5..4dfce7758b 100644 --- a/crates/plugins/src/effect.rs +++ b/crates/plugins/src/effect.rs @@ -714,12 +714,16 @@ mod tests { let _lock = crate::safe_mode::TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); crate::safe_mode::set_active(None); const ID: &str = "test.effect.deferfailed"; - // Runs to its instruction budget. + // Runs to its instruction budget: 100,000 instructions, not the default 50 million and 4,000 + // per byte of input. The view's budget is measured in real time, and a run that the view's + // budget cuts short is deferred for time, not as failed. let src = crate::wat::spinning(&crate::wat::manifest(ID, "effect", "{}"), 1_000_000_000, r#"{"objects":[]}"#); - registry::install(crate::Plugin::load(&wat::parse_str(&src).unwrap(), Limits::default()).unwrap()).unwrap(); + let limits = Limits { fuel_base: 100_000, fuel_per_byte: 0, ..Limits::default() }; + registry::install(crate::Plugin::load(&wat::parse_str(&src).unwrap(), limits).unwrap()).unwrap(); let view = crate::deferred::Deferrals::with_clock(stepping(1)); assert!(!view.view(|| drawn(ID, &line(2), 0))); - assert!(last_error(ID).is_some()); + let e = last_error(ID).unwrap_or_default(); + assert!(e.contains("instruction budget"), "{e}"); assert!(!view.view(|| drawn("test.effect.notinstalled", &line(2), 1))); let reasons = |v: &crate::deferred::Deferrals| v.list().iter().map(|d| d.reason).collect::>(); assert_eq!(reasons(&view), [Reason::Failed, Reason::Missing]);