Watchfire
v0.1
Testing agents
Testing. TestApp leaves Watchfire off (dispatched jobs wait in the queue); TestApp::new(build).with_agents()
starts it. smeltery::watchfire::testing::Harness runs agents under the real supervisor on paused Tokio time with a
fake HTTP transport (http::FakeTransport: canned answers by method and URL, every request recorded):
use smeltery::watchfire::prelude::*;
use smeltery::watchfire::testing::Harness;
// In a #[tokio::test(start_paused = true)] function:
let mut h = Harness::new(agent_fn("flaky", |ctx: AgentCtx| async move {
ctx.sleep(1.secs()).await;
Err(AgentError::msg("boom"))
}))
.config(AgentConfig::default().backoff(1.secs()..=8.secs()));
h.start().await.unwrap();
h.advance(1.secs()).await;
assert_eq!(h.state(), AgentState::BackingOff);
assert!(h.next_backoff().unwrap() <= 1.secs());
h.advance(10.secs()).await;
assert!(h.restarts() >= 1);
assert_eq!(h.runs().await[0].outcome, RunOutcome::Failed);
h.shutdown().await;
Harness also has transitions() (every state in order), runs(), logs(), stop(), agents() and
Harness::from_watchfire(w) for a whole registration; JobHarness::new().await.run(&job) runs a job's handle
(JobHarness::for_app(app).await runs it inside a given app, e.g. a TestApp's with its database and services)
directly.