fix: change where TaskHandle is borrowed to prevent repeat output fetches
This commit is contained in:
1 parent
c8efb00175
commit
9fbe4c2fd8
47 files changed
+323
-513
No files matched your search
+14
-14
@@ -16,12 +16,12 @@ async fn test_linear_error_propagation() {
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| -> i32 {
|
||||
panic!("Error at t2 with input {}", x);
|
||||
}))
|
||||
.depends_on(t1);
|
||||
.depends_on(&t1);
|
||||
let t3 = dag
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x + 1))
|
||||
.depends_on(t2);
|
||||
.depends_on(&t2);
|
||||
dag.add_task(task_fn::<i32, _, _>(|&x: &i32| x * 2))
|
||||
.depends_on(t3);
|
||||
.depends_on(&t3);
|
||||
|
||||
assert!(matches!(
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
@@ -44,16 +44,16 @@ async fn test_diamond_error_propagation() {
|
||||
|
||||
let left = dag
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x / 2))
|
||||
.depends_on(source);
|
||||
.depends_on(&source);
|
||||
|
||||
let right = dag
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| {
|
||||
panic!("Right path fails with {}", x);
|
||||
}))
|
||||
.depends_on(source);
|
||||
.depends_on(&source);
|
||||
|
||||
dag.add_task(task_fn::<(i32, i32), _, _>(|(l, r): (&i32, &i32)| l + r))
|
||||
.depends_on((left, right));
|
||||
.depends_on((&left, &right));
|
||||
|
||||
assert!(matches!(
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
@@ -73,7 +73,7 @@ async fn test_error_in_wide_fanout() {
|
||||
// Create wide fanout from failing source
|
||||
for i in 0..20 {
|
||||
dag.add_task(task_fn::<i32, _, _>(move |&x: &i32| x + i))
|
||||
.depends_on(source);
|
||||
.depends_on(&source);
|
||||
}
|
||||
|
||||
assert!(matches!(
|
||||
@@ -102,7 +102,7 @@ async fn test_selective_error_propagation() {
|
||||
}
|
||||
},
|
||||
))
|
||||
.depends_on(source);
|
||||
.depends_on(&source);
|
||||
|
||||
// Further processing
|
||||
let final_task = dag
|
||||
@@ -113,7 +113,7 @@ async fn test_selective_error_propagation() {
|
||||
format!("Success: {}", val)
|
||||
}
|
||||
}))
|
||||
.depends_on(handler);
|
||||
.depends_on(&handler);
|
||||
|
||||
let mut output = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
@@ -121,13 +121,13 @@ async fn test_selective_error_propagation() {
|
||||
.unwrap();
|
||||
|
||||
// Source returns an Err variant (not a panic)
|
||||
assert_eq!(output.get(source).unwrap(), Err("Source error".to_string()));
|
||||
assert_eq!(output.get(source), Err("Source error".to_string()));
|
||||
|
||||
// Handler processes it
|
||||
assert_eq!(output.get(handler).unwrap(), -1);
|
||||
assert_eq!(output.get(handler), -1);
|
||||
|
||||
// Final task handles the error case
|
||||
assert_eq!(output.get(final_task).unwrap(), "Handled error case");
|
||||
assert_eq!(output.get(final_task), "Handled error case");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -169,7 +169,7 @@ async fn test_error_propagation_timing() {
|
||||
.add_task(T2Task {
|
||||
order: propagation_order.clone(),
|
||||
})
|
||||
.depends_on(t1);
|
||||
.depends_on(&t1);
|
||||
|
||||
let _t3 = dag
|
||||
.add_task(task_fn::<i32, _, _>({
|
||||
@@ -180,7 +180,7 @@ async fn test_error_propagation_timing() {
|
||||
x + 1
|
||||
}
|
||||
}))
|
||||
.depends_on(t2);
|
||||
.depends_on(&t2);
|
||||
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
|
||||
+10
-10
@@ -34,7 +34,7 @@ async fn test_retry_pattern_simulation() -> DagResult<()> {
|
||||
.await?;
|
||||
|
||||
// Task completes with error on first "attempt"
|
||||
assert_eq!(output.get(task)?, Err("Simulated failure"));
|
||||
assert_eq!(output.get(task), Err("Simulated failure"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -78,7 +78,7 @@ async fn test_circuit_breaker_pattern() -> DagResult<()> {
|
||||
|
||||
// First few tasks fail and open circuit
|
||||
for task in tasks.into_iter().take(4) {
|
||||
assert!(output.get(task)?.is_err());
|
||||
assert!(output.get(task).is_err());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -120,8 +120,8 @@ async fn test_error_accumulation_pattern() -> DagResult<()> {
|
||||
let [first, second] = <[_; 2]>::try_from(tasks).map_err(|_e| ()).unwrap();
|
||||
|
||||
// Verify specific results
|
||||
assert!(output.get(first)?.is_err());
|
||||
assert_eq!(output.get(second)?, Ok(1));
|
||||
assert!(output.get(first).is_err());
|
||||
assert_eq!(output.get(second), Ok(1));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -136,29 +136,29 @@ async fn test_error_boundary_isolation() -> DagResult<()> {
|
||||
.add_task(task_fn::<i32, _, _>(|_x: &i32| {
|
||||
Err::<i32, &str>("Group A error")
|
||||
}))
|
||||
.depends_on(a1);
|
||||
.depends_on(&a1);
|
||||
|
||||
// Group B: should be isolated from Group A's error
|
||||
let b1 = dag.add_task(task_fn::<(), _, _>(|_: ()| 20));
|
||||
let b2 = dag
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x * 2))
|
||||
.depends_on(b1);
|
||||
.depends_on(&b1);
|
||||
|
||||
// Group C: depends on B but not A
|
||||
let c1 = dag
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x + 5))
|
||||
.depends_on(b2);
|
||||
.depends_on(&b2);
|
||||
|
||||
let mut output = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// Group A fails (returns Err)
|
||||
assert_eq!(output.get(a2)?, Err("Group A error"));
|
||||
assert_eq!(output.get(a2), Err("Group A error"));
|
||||
|
||||
// Groups B and C succeed
|
||||
assert_eq!(output.get(b2)?, 40);
|
||||
assert_eq!(output.get(c1)?, 45);
|
||||
assert_eq!(output.get(b2), 40);
|
||||
assert_eq!(output.get(c1), 45);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user