mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
test(plugins): exercise fuel renewal with explicit CPU work (#3438)
Keeps main's 40,000 foreground fuel budget and patient CPU workload, and adds a quiet mode that runs the same workload without task reports and must exhaust the scaled budget, so beginning a task alone is shown not to renew it. The Git capability setup now fails the test instead of returning early. Production limits are unchanged. Co-authored-by: amphetamlne <55946742+amphetamlne@users.noreply.github.com>
This commit is contained in:
@@ -879,16 +879,15 @@ fn background_tasks_scale_and_renew_cpu_fuel_budget() {
|
||||
// Room for activation (about 3_100 on macOS, more on Windows). A background task gets ten
|
||||
// times it (5 s / 500 ms): enough for each step of `patient` with its CPU work (32_000 to
|
||||
// 80_000), not for the whole run without the refill on each report.
|
||||
let f = fixture(Limits {
|
||||
let limits = Limits {
|
||||
fuel: 40_000,
|
||||
timeout: Duration::from_millis(500),
|
||||
background: Duration::from_millis(5_000),
|
||||
..Limits::default()
|
||||
});
|
||||
};
|
||||
let f = fixture(limits);
|
||||
f.install(&misbehave_pkg());
|
||||
if f.host.set_capability("misbehave", "process:git", true).is_err() {
|
||||
return;
|
||||
}
|
||||
f.host.set_capability("misbehave", "process:git", true).expect("grant Git capability");
|
||||
// Warm up activation in its own call so `patient` starts with a fresh budget.
|
||||
assert_eq!(f.run("misbehave", "echo", Some("warm")).unwrap().as_deref(), Some("warm"));
|
||||
|
||||
@@ -897,6 +896,13 @@ fn background_tasks_scale_and_renew_cpu_fuel_budget() {
|
||||
|
||||
let err = f.run("misbehave", "spin", None).unwrap_err();
|
||||
assert!(err.contains("exceeded its CPU budget (40000 fuel per call)"), "{err}");
|
||||
|
||||
// Beginning a task alone must not renew its scaled budget.
|
||||
let quiet = fixture(limits);
|
||||
quiet.install(&misbehave_pkg());
|
||||
quiet.host.set_capability("misbehave", "process:git", true).expect("grant Git capability");
|
||||
let err = quiet.run("misbehave", "patient", Some("quiet:4000")).unwrap_err();
|
||||
assert!(err.contains("exceeded its CPU budget (400000 fuel per call)"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
1056d650117bc2216ac518aa26b27cf898f58db62369ae285b9d8925ada74dff
|
||||
b24fb8d5161006104698fb07a43432601b4f16fdc4a34cc70058cbef7e973066
|
||||
|
||||
+9
-3
@@ -181,9 +181,13 @@ impl commands::Guest for Misbehave {
|
||||
};
|
||||
let child = process::start(&cmd, None)?;
|
||||
// CPU work per step (loop iterations), for fuel budget tests.
|
||||
let work: u64 = arg.as_deref().and_then(|a| a.parse().ok()).unwrap_or(0);
|
||||
let arg = arg.as_deref().unwrap_or("");
|
||||
let report = !arg.starts_with("quiet:");
|
||||
let work: u64 = arg.strip_prefix("quiet:").unwrap_or(arg).parse().unwrap_or(0);
|
||||
for step in 0..25 {
|
||||
task.report(step, Some(25), Some("waiting"));
|
||||
if report {
|
||||
task.report(step, Some(25), Some("waiting"));
|
||||
}
|
||||
let mut x: u64 = 0;
|
||||
for _ in 0..work {
|
||||
x = std::hint::black_box(x.wrapping_add(1));
|
||||
@@ -195,7 +199,9 @@ impl commands::Guest for Misbehave {
|
||||
// Let it finish on its own: no kill, no slow teardown.
|
||||
child.close_stdin()?;
|
||||
let _ = child.wait(5_000);
|
||||
task.report(25, Some(25), Some("done"));
|
||||
if report {
|
||||
task.report(25, Some(25), Some("done"));
|
||||
}
|
||||
Ok(Some("still here".into()))
|
||||
}
|
||||
// `editor.write` is not granted: an error, not a trap.
|
||||
|
||||
Reference in New Issue
Block a user