use crate::ExecutionResult;
use super::common::{MathContext, SingleAdd, SingleAddInputs};
#[tokio::test]
async fn pause_preserves_state() {
let saga = SingleAdd::new(SingleAddInputs {
add: ("x".into(), 1, 2),
});
let mut ctx = MathContext::default();
ctx.pause_after = Some(0);
let exec = saga.build(ctx);
match exec.start().await {
ExecutionResult::Paused(e) => {
assert_eq!(e.context().r.get("x").copied(), Some(3));
}
other => panic!("Expected Paused, got {:?}", std::mem::discriminant(&other)),
}
}
#[tokio::test]
async fn paused_execution_serializes() {
let saga = SingleAdd::new(SingleAddInputs {
add: ("x".into(), 1, 2),
});
let mut ctx = MathContext::default();
ctx.pause_after = Some(0);
let exec = saga.build(ctx);
match exec.start().await {
ExecutionResult::Paused(e) => {
let json = serde_json::to_string(&e).expect("should serialize");
assert!(json.contains("\"x\""), "JSON should contain register name");
assert!(json.contains("3"), "JSON should contain computed value");
}
other => panic!("Expected Paused, got {:?}", std::mem::discriminant(&other)),
}
}