Update tests, examples, benches
This commit is contained in:
1 parent
bacac903b3
commit
85ccd7e507
89 files changed
+942
-1785
No files matched your search
+54
-91
@@ -10,6 +10,7 @@
|
||||
//! These tests serve as both validation and documentation for proper Arc usage.
|
||||
|
||||
use dagx::{task, DagRunner, Task};
|
||||
use futures::FutureExt;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -43,11 +44,9 @@ async fn test_arc_basic_pipeline() {
|
||||
let producer = dag.add_task(Producer);
|
||||
let consumer = dag.add_task(Consumer).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: producer is not a sink (consumer depends on it), so we can't get() its value
|
||||
// Only sink nodes (nodes with no dependents) store their outputs for retrieval
|
||||
@@ -101,11 +100,9 @@ async fn test_arc_with_primitives() {
|
||||
.add_task(AllConsumer)
|
||||
.depends_on((&i32_prod, &f64_prod, &bool_prod));
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: producers are not sinks (consumer depends on them), so we can't get() their values
|
||||
// The consumer output verifies all three producers worked correctly
|
||||
@@ -177,11 +174,9 @@ async fn test_arc_with_collections() {
|
||||
.add_task(CollectionConsumer)
|
||||
.depends_on((&vec_prod, &map_prod, &set_prod));
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: producers are not sinks (consumer depends on them), so we can't get() their values
|
||||
// The consumer output verifies all three collection producers worked correctly
|
||||
@@ -250,11 +245,9 @@ async fn test_arc_with_custom_structs() {
|
||||
let age_ext = dag.add_task(AgeExtractor).depends_on(&person_prod);
|
||||
let email_ext = dag.add_task(EmailCountExtractor).depends_on(&person_prod);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: person_prod is not a sink (3 extractors depend on it), so we can't get() its value
|
||||
// The extractor outputs verify the person was created and shared correctly
|
||||
@@ -318,11 +311,9 @@ async fn test_arc_fan_out_three_consumers() {
|
||||
let c2 = dag.add_task(FirstConsumer).depends_on(&producer);
|
||||
let c3 = dag.add_task(JoinConsumer).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(c1).unwrap(), 5);
|
||||
assert_eq!(dag.get(c2).unwrap(), "item1");
|
||||
@@ -394,11 +385,9 @@ async fn test_arc_fan_out_five_consumers_large_data() {
|
||||
let c4 = dag.add_task(PatternCounter).depends_on(&producer);
|
||||
let c5 = dag.add_task(TotalBytesComputer).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: producer is not a sink (has 5 consumers), so we can't get() its value
|
||||
// We verify correctness through the consumer outputs instead
|
||||
@@ -486,11 +475,9 @@ async fn test_arc_nested_fan_out_tree() {
|
||||
let l2_negate = dag.add_task(Level2Negate).depends_on(l1_prod);
|
||||
let l2_mod = dag.add_task(Level2Mod10).depends_on(l1_prod);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: l1_sum and l1_prod are not sinks (they have level 2 tasks depending on them)
|
||||
// Only the level 2 tasks are sinks and can be retrieved
|
||||
@@ -556,11 +543,9 @@ async fn test_arc_performance_vs_clone() {
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
@@ -658,11 +643,9 @@ async fn test_arc_with_result() {
|
||||
|
||||
let consumer3 = dag.add_task(ArcResultConsumer2).depends_on(&arc_result_err);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(consumer1).unwrap(), "Got Ok: Success");
|
||||
assert_eq!(dag.get(consumer2).unwrap(), "Got Arc: Success");
|
||||
@@ -767,11 +750,9 @@ async fn test_arc_with_option() {
|
||||
let c3 = dag.add_task(OptionArcConsumer1).depends_on(&opt_arc_some);
|
||||
let c4 = dag.add_task(OptionArcConsumer2).depends_on(&opt_arc_none);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(c1).unwrap(), "Some(42)");
|
||||
assert_eq!(dag.get(c2).unwrap(), "None");
|
||||
@@ -824,11 +805,9 @@ async fn test_arc_diamond_dependency() {
|
||||
let right = dag.add_task(RightBranch).depends_on(&top);
|
||||
let bottom = dag.add_task(Bottom).depends_on((&left, &right));
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(bottom).unwrap(), "Sum: 15, Product: 120");
|
||||
}
|
||||
@@ -894,11 +873,9 @@ async fn test_arc_empty_collections() {
|
||||
.add_task(EmptyConsumer)
|
||||
.depends_on((&vec_task, &string_task, &map_task));
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
dag.get(consumer).unwrap(),
|
||||
@@ -967,11 +944,9 @@ async fn test_arc_very_large_data() {
|
||||
let last = dag.add_task(LastSampler).depends_on(&producer);
|
||||
let middle = dag.add_task(MiddleSampler).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(counter).unwrap(), SIZE);
|
||||
assert!(dag.get(first).unwrap().contains("Item number 0"));
|
||||
@@ -1006,11 +981,9 @@ async fn test_arc_of_arc() {
|
||||
let producer = dag.add_task(NestedProducer);
|
||||
let consumer = dag.add_task(NestedConsumer).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(dag.get(consumer).unwrap(), "Value: Nested Arc");
|
||||
}
|
||||
@@ -1072,11 +1045,9 @@ async fn test_arc_mixed_with_non_arc() {
|
||||
let unwrap = dag.add_task(Unwrapper).depends_on(&arc_prod);
|
||||
let wrap = dag.add_task(Wrapper).depends_on(&non_arc_prod);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
dag.get(mixed).unwrap(),
|
||||
@@ -1142,11 +1113,9 @@ async fn test_arc_parallel_execution() {
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
@@ -1193,11 +1162,9 @@ async fn test_arc_reference_counting() {
|
||||
let producer = dag.add_task(RefCountProducer);
|
||||
let checker = dag.add_task(RefCountChecker).depends_on(&producer);
|
||||
|
||||
dag.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
dag.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Note: producer is not a sink (checker depends on it), so we can't get() its value
|
||||
// The checker task verifies the Arc was passed correctly
|
||||
@@ -1271,9 +1238,7 @@ async fn test_arc_massive_fanout_performance_comparison() {
|
||||
|
||||
let start_without_arc = Instant::now();
|
||||
dag_without_arc
|
||||
.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
let duration_without_arc = start_without_arc.elapsed();
|
||||
@@ -1325,9 +1290,7 @@ async fn test_arc_massive_fanout_performance_comparison() {
|
||||
|
||||
let start_with_arc = Instant::now();
|
||||
dag_with_arc
|
||||
.run(|fut| {
|
||||
tokio::spawn(fut);
|
||||
})
|
||||
.run(|fut| tokio::spawn(fut).map(Result::unwrap))
|
||||
.await
|
||||
.unwrap();
|
||||
let duration_with_arc = start_with_arc.elapsed();
|
||||
|
||||
Reference in new issue
Block a user