Make node graph test syncronous

This commit is contained in:
Dennis Kobert 2023-05-31 09:36:08 +02:00 committed by Keavon Chambers
parent 7525be5c7a
commit 75fe423f40
5 changed files with 23 additions and 18 deletions

1
Cargo.lock generated
View file

@ -2216,7 +2216,6 @@ dependencies = [
"num-traits",
"once_cell",
"serde",
"tokio",
]
[[package]]

View file

@ -187,7 +187,8 @@ impl Operation {
/// This function reads from uninitialized memory but the generated value should be fine.
pub fn pseudo_hash(&self) -> u64 {
let mut s = DefaultHasher::new();
unsafe { self.to_byte_vec() }.hash(&mut s);
//unsafe { self.to_byte_vec() }.hash(&mut s);
std::mem::discriminant(self).hash(&mut s);
s.finish()
}
}

View file

@ -13,10 +13,13 @@ quantization = ["graphene-std/quantization"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = ["async", "std" ] }
graphene-core = { path = "../gcore", features = ["async", "std"] }
graphene-std = { path = "../gstd" }
graph-craft = { path = "../graph-craft" }
dyn-any = { path = "../../libraries/dyn-any", features = ["log-bad-types", "glam"] }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"glam",
] }
num-traits = "0.2"
dyn-clone = "1.0"
log = "0.4"
@ -24,6 +27,3 @@ serde = { version = "1", features = ["derive"], optional = true }
glam = { version = "0.22" }
once_cell = "1.17.0"
futures = "0.3.28"
[dev-dependencies]
tokio = { version = "1.12", features = ["rt", "macros"] }

View file

@ -226,12 +226,15 @@ mod test {
use super::*;
#[tokio::test]
async fn push_node() {
#[test]
fn push_node_sync() {
let mut tree = BorrowTree::default();
let val_1_protonode = ProtoNode::value(ConstructionArgs::Value(TaggedValue::U32(2u32)), vec![]);
tree.push_node(0, val_1_protonode, &TypingContext::default()).await.unwrap();
let context = TypingContext::default();
let future = tree.push_node(0, val_1_protonode, &context); //.await.unwrap();
futures::executor::block_on(future).unwrap();
let _node = tree.get(0).unwrap();
assert_eq!(tree.eval(0, ()).await, Some(2u32));
let result = futures::executor::block_on(tree.eval(0, ()));
assert_eq!(result, Some(2u32));
}
}

View file

@ -10,8 +10,10 @@ mod tests {
use graphene_core::*;
use std::borrow::Cow;
#[tokio::test]
async fn execute_add() {
use futures::executor::block_on;
#[test]
fn execute_add() {
use graph_craft::document::*;
use graph_craft::*;
@ -75,15 +77,15 @@ mod tests {
let compiler = Compiler {};
let protograph = compiler.compile_single(network, true).expect("Graph should be generated");
let exec = DynamicExecutor::new(protograph).await.unwrap_or_else(|e| panic!("Failed to create executor: {}", e));
let exec = block_on(DynamicExecutor::new(protograph)).unwrap_or_else(|e| panic!("Failed to create executor: {}", e));
let result = exec.execute(32_u32.into_dyn()).await.unwrap();
let result = block_on(exec.execute(32_u32.into_dyn())).unwrap();
let val = *dyn_any::downcast::<u32>(result).unwrap();
assert_eq!(val, 33_u32);
}
#[tokio::test]
async fn double_number() {
#[test]
fn double_number() {
use graph_craft::document::*;
use graph_craft::*;
@ -124,6 +126,6 @@ mod tests {
let compiler = Compiler {};
let protograph = compiler.compile_single(network, true).expect("Graph should be generated");
let _exec = DynamicExecutor::new(protograph).await.map(|e| panic!("The network should not type check: {:#?}", e)).unwrap_err();
let _exec = block_on(DynamicExecutor::new(protograph)).map(|e| panic!("The network should not type check: {:#?}", e)).unwrap_err();
}
}