use std::sync::Arc;
use crate::node::{ExecutableNode, TypedNode};
struct TestTask {
value: i32,
}
#[crate::task]
impl TestTask {
async fn run(&self) -> i32 {
self.value
}
}
struct TaskWithDependency;
#[crate::task]
impl TaskWithDependency {
async fn run(input: &i32) -> i32 {
input * 2
}
}
#[tokio::test]
async fn test_execute_with_deps_success() {
let dependency_node = Box::new(TypedNode::new(TestTask { value: 21 }));
let dependent_node = Box::new(TypedNode::new(TaskWithDependency));
let dep_dependencies = vec![];
let dep_result =
tokio::spawn(async move { dependency_node.execute_with_deps(dep_dependencies).await })
.await
.unwrap()
.unwrap();
let dependencies = vec![dep_result as Arc<dyn std::any::Any + Send + Sync>];
let result = dependent_node.execute_with_deps(dependencies).await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_execute_with_deps_sink_node() {
let node = Box::new(TypedNode::new(TestTask { value: 42 }));
let dependencies = vec![];
let result = node.execute_with_deps(dependencies).await;
assert!(result.is_ok());
let output = result.unwrap();
let arc_value = output.downcast::<i32>().unwrap();
assert_eq!(*arc_value, 42);
}
#[tokio::test]
async fn test_execute_with_deps_non_sink_node() {
let node = TypedNode::new(TestTask { value: 42 });
let node = Box::new(node);
let result = node.execute_with_deps(vec![]).await;
assert!(result.is_ok());
let arc_value = result.unwrap().downcast::<i32>().unwrap();
assert_eq!(*arc_value, 42);
}