Depend on futures-util instead of futures
This commit is contained in:
1 parent
f342e33f16
commit
a75defa5a6
79 files changed
+447
-380
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
use crate::common::task_fn;
|
||||
use dagx::{DagError, DagRunner, TaskHandle};
|
||||
use futures::FutureExt;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_result_not_found_error() {
|
||||
@@ -15,7 +14,7 @@ async fn test_result_not_found_error() {
|
||||
assert!(matches!(result, Err(DagError::ResultNotFound { .. })));
|
||||
|
||||
// Run and verify it works after
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -33,7 +32,7 @@ async fn test_nested_result_error_handling() {
|
||||
|
||||
let task2 = dag.add_task(task_fn::<(), _, _>(|_: ()| Result::<i32, String>::Ok(42)));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -48,7 +47,7 @@ async fn test_option_none_not_error() {
|
||||
|
||||
let task = dag.add_task(task_fn::<(), _, _>(|_: ()| None::<i32>));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -77,7 +76,7 @@ async fn test_custom_error_types() {
|
||||
})
|
||||
}));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -106,7 +105,9 @@ async fn test_error_in_tuple_dependency() {
|
||||
.add_task(task_fn::<(i32, i32), _, _>(|(a, b): (&i32, &i32)| a + b))
|
||||
.depends_on((ok_task, err_task));
|
||||
|
||||
let result = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let result = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
assert!(result.is_err());
|
||||
assert!(dag.get(dependent).is_err());
|
||||
@@ -124,7 +125,9 @@ async fn test_string_panic_vs_structured_panic() {
|
||||
panic!("Formatted panic: value={}, code={}", 42, "ERROR");
|
||||
}));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// Both should result in errors
|
||||
assert!(dag.get(string_panic).is_err());
|
||||
@@ -144,7 +147,7 @@ async fn test_anyhow_like_error_chain() {
|
||||
outer
|
||||
}));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::common::task_fn;
|
||||
use dagx::{task, DagRunner, TaskHandle};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
@@ -25,7 +25,9 @@ async fn test_linear_error_propagation() {
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x * 2))
|
||||
.depends_on(t3);
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// t1 succeeds
|
||||
assert_eq!(dag.get(t1).unwrap(), 1);
|
||||
@@ -64,7 +66,9 @@ async fn test_diamond_error_propagation() {
|
||||
.add_task(task_fn::<(i32, i32), _, _>(|(l, r): (&i32, &i32)| l + r))
|
||||
.depends_on((&left, &right));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
assert_eq!(dag.get(source).unwrap(), 100);
|
||||
assert_eq!(dag.get(left).unwrap(), 50);
|
||||
@@ -110,7 +114,9 @@ async fn test_error_stops_at_boundary() {
|
||||
}
|
||||
}));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// Error branch: source runs but dependent doesn't
|
||||
assert!(dag.get(error_source).is_err());
|
||||
@@ -149,7 +155,9 @@ async fn test_multiple_error_sources_convergence() {
|
||||
))
|
||||
.depends_on((&error1, &error2, &success));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// All error sources fail
|
||||
assert!(dag.get(error1).is_err());
|
||||
@@ -180,7 +188,9 @@ async fn test_error_in_wide_fanout() {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// Source fails
|
||||
assert!(dag.get(source).is_err());
|
||||
@@ -225,7 +235,7 @@ async fn test_selective_error_propagation() {
|
||||
}))
|
||||
.depends_on(handler);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -291,7 +301,9 @@ async fn test_error_propagation_timing() {
|
||||
}))
|
||||
.depends_on(t2);
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
let order = propagation_order.lock().clone();
|
||||
|
||||
@@ -364,7 +376,7 @@ async fn test_partial_branch_failure_propagation() {
|
||||
))
|
||||
.depends_on((&a3, &b3, &c3));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::common::task_fn;
|
||||
use dagx::{DagResult, DagRunner};
|
||||
use futures::FutureExt;
|
||||
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -24,7 +24,9 @@ async fn test_fallback_on_error() -> DagResult<()> {
|
||||
let _selector = dag.add_task(task_fn::<(), _, _>(|_: ()| {}));
|
||||
|
||||
// Run DAG
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// Primary should fail
|
||||
assert!(dag.get(primary).is_err());
|
||||
@@ -58,7 +60,8 @@ async fn test_retry_pattern_simulation() -> DagResult<()> {
|
||||
}
|
||||
}));
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// Task completes with error on first "attempt"
|
||||
assert_eq!(dag.get(task)?, Err("Simulated failure"));
|
||||
@@ -99,7 +102,8 @@ async fn test_circuit_breaker_pattern() -> DagResult<()> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// First few tasks fail and open circuit
|
||||
for task in tasks.into_iter().take(4) {
|
||||
@@ -131,7 +135,9 @@ async fn test_partial_recovery_with_defaults() -> DagResult<()> {
|
||||
vec![0, 10, 20, 0, 40, 50, 0, 70, 80, 0] // 0 for failed tasks
|
||||
}));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
let result = dag.get(aggregator)?;
|
||||
assert_eq!(result.len(), 10);
|
||||
@@ -159,7 +165,8 @@ async fn test_error_accumulation_pattern() -> DagResult<()> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// Check accumulated errors
|
||||
let error_list = errors.lock().clone();
|
||||
@@ -197,7 +204,8 @@ async fn test_graceful_degradation() -> DagResult<()> {
|
||||
}))
|
||||
.depends_on(critical);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// Critical path works
|
||||
assert_eq!(dag.get(final_task)?, 15);
|
||||
@@ -228,7 +236,8 @@ async fn test_error_boundary_isolation() -> DagResult<()> {
|
||||
.add_task(task_fn::<i32, _, _>(|&x: &i32| x + 5))
|
||||
.depends_on(b2);
|
||||
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await?;
|
||||
dag.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await?;
|
||||
|
||||
// Group A fails (returns Err)
|
||||
assert_eq!(dag.get(a2)?, Err("Group A error"));
|
||||
@@ -261,7 +270,9 @@ async fn test_compensation_action() -> DagResult<()> {
|
||||
}
|
||||
}));
|
||||
|
||||
let _ = dag.run(|fut| tokio::spawn(fut).map(Result::unwrap)).await;
|
||||
let _ = dag
|
||||
.run(|fut| async move { tokio::spawn(fut).await.unwrap() })
|
||||
.await;
|
||||
|
||||
// Action failed
|
||||
assert!(dag.get(action).is_err());
|
||||
|
||||
Reference in new issue
Block a user