mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 06:38:12 +08:00
Fix tests
This commit is contained in:
+10
-11
@@ -12,7 +12,6 @@ use crate::test_utils::test_prelude::LayerNodeIdentifier;
|
|||||||
use glam::DVec2;
|
use glam::DVec2;
|
||||||
use graph_craft::document::DocumentNode;
|
use graph_craft::document::DocumentNode;
|
||||||
use graphene_std::InputAccessor;
|
use graphene_std::InputAccessor;
|
||||||
use graphene_std::any::EditorContext;
|
|
||||||
use graphene_std::raster::color::Color;
|
use graphene_std::raster::color::Color;
|
||||||
|
|
||||||
/// A set of utility functions to make the writing of editor test more declarative
|
/// A set of utility functions to make the writing of editor test more declarative
|
||||||
@@ -22,20 +21,20 @@ pub struct EditorTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EditorTestUtils {
|
impl EditorTestUtils {
|
||||||
pub fn create() -> Self {
|
// pub fn create() -> Self {
|
||||||
let _ = env_logger::builder().is_test(true).try_init();
|
// let _ = env_logger::builder().is_test(true).try_init();
|
||||||
set_uuid_seed(0);
|
// set_uuid_seed(0);
|
||||||
|
|
||||||
let (mut editor, runtime) = Editor::new_local_executor();
|
// let (mut editor, runtime) = Editor::new_local_executor();
|
||||||
|
|
||||||
// We have to set this directly instead of using `GlobalsMessage::SetPlatform` because race conditions with multiple tests can cause that message handler to set it more than once, which is a failure.
|
// // We have to set this directly instead of using `GlobalsMessage::SetPlatform` because race conditions with multiple tests can cause that message handler to set it more than once, which is a failure.
|
||||||
// It isn't sufficient to guard the message dispatch here with a check if the once_cell is empty, because that isn't atomic and the time between checking and handling the dispatch can let multiple through.
|
// // It isn't sufficient to guard the message dispatch here with a check if the once_cell is empty, because that isn't atomic and the time between checking and handling the dispatch can let multiple through.
|
||||||
let _ = GLOBAL_PLATFORM.set(Platform::Windows).is_ok();
|
// let _ = GLOBAL_PLATFORM.set(Platform::Windows).is_ok();
|
||||||
|
|
||||||
editor.handle_message(PortfolioMessage::Init);
|
// editor.handle_message(PortfolioMessage::Init);
|
||||||
|
|
||||||
Self { editor, runtime }
|
// Self { editor, runtime }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// pub fn eval_graph<'a>(&'a mut self) -> impl std::future::Future<Output = Result<Instrumented, String>> + 'a {
|
// pub fn eval_graph<'a>(&'a mut self) -> impl std::future::Future<Output = Result<Instrumented, String>> + 'a {
|
||||||
// // An inner function is required since async functions in traits are a bit weird
|
// // An inner function is required since async functions in traits are a bit weird
|
||||||
|
|||||||
@@ -93,9 +93,12 @@ where
|
|||||||
|
|
||||||
drop(cache_guard);
|
drop(cache_guard);
|
||||||
|
|
||||||
|
let fut = self.node.eval(input);
|
||||||
|
let cache = self.cache.clone();
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let value = self.node.eval(input).await;
|
let value = fut.await;
|
||||||
*self.cache.lock().unwrap() = Some((hash, Arc::new(value.clone())));
|
*cache.lock().unwrap() = Some((hash, Arc::new(value.clone())));
|
||||||
value
|
value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use crate::instances::{InstanceRef, Instances};
|
use crate::instances::{InstanceRef, Instances};
|
||||||
use crate::raster_types::{CPU, RasterDataTable};
|
use crate::raster_types::{CPU, RasterDataTable};
|
||||||
use crate::vector::VectorDataTable;
|
use crate::vector::VectorDataTable;
|
||||||
use crate::{ Context, Ctx, ExtractIndex, ExtractVarArgs, GraphicElement, GraphicGroupTable, WithIndex};
|
use crate::{Context, Ctx, ExtractIndex, ExtractVarArgs, GraphicElement, GraphicGroupTable, WithIndex};
|
||||||
use glam::DVec2;
|
use glam::DVec2;
|
||||||
|
|
||||||
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
|
#[node_macro::node(name("Instance on Points"), category("Instancing"), path(graphene_core::vector))]
|
||||||
async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
|
async fn instance_on_points<T: Into<GraphicElement> + Default + Send + Clone + 'static>(
|
||||||
ctx: impl Ctx + WithIndex,
|
ctx: impl Ctx + WithIndex + Sync,
|
||||||
points: VectorDataTable,
|
points: VectorDataTable,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
|
|||||||
@@ -397,7 +397,6 @@ impl Display for TaggedValue {
|
|||||||
|
|
||||||
pub struct UpcastNode {
|
pub struct UpcastNode {
|
||||||
value: MemoHash<TaggedValue>,
|
value: MemoHash<TaggedValue>,
|
||||||
inspected: Cell<bool>,
|
|
||||||
}
|
}
|
||||||
impl<'input> Node<'input, DAny<'input>> for UpcastNode {
|
impl<'input> Node<'input, DAny<'input>> for UpcastNode {
|
||||||
type Output = FutureAny<'input>;
|
type Output = FutureAny<'input>;
|
||||||
@@ -407,13 +406,12 @@ impl<'input> Node<'input, DAny<'input>> for UpcastNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn introspect(&self) -> graphene_core::memo::MonitorIntrospectResult {
|
fn introspect(&self) -> graphene_core::memo::MonitorIntrospectResult {
|
||||||
let inspected = self.inspected.replace(true);
|
graphene_core::memo::MonitorIntrospectResult::Evaluated((Arc::new(self.value.clone().into_inner()) as Arc<dyn std::any::Any + Send + Sync>, true))
|
||||||
graphene_core::memo::MonitorIntrospectResult::Evaluated((Arc::new(self.value.clone().into_inner()) as Arc<dyn std::any::Any + Send + Sync>, !inspected))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl UpcastNode {
|
impl UpcastNode {
|
||||||
pub fn new(value: MemoHash<TaggedValue>) -> Self {
|
pub fn new(value: MemoHash<TaggedValue>) -> Self {
|
||||||
Self { value, inspected: Cell::new(false) }
|
Self { value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Default, Debug, Clone, Copy)]
|
#[derive(Default, Debug, Clone, Copy)]
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use graph_craft::proto::{ProtoNetwork, ProtoNode};
|
|||||||
use graph_craft::util::load_network;
|
use graph_craft::util::load_network;
|
||||||
use graph_craft::wasm_application_io::{EditorPreferences, WasmApplicationIoValue};
|
use graph_craft::wasm_application_io::{EditorPreferences, WasmApplicationIoValue};
|
||||||
use graphene_core::text::FontCache;
|
use graphene_core::text::FontCache;
|
||||||
use graphene_std::any::EditorContext;
|
|
||||||
use graphene_std::application_io::{ApplicationIo, ApplicationIoValue, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
|
use graphene_std::application_io::{ApplicationIo, ApplicationIoValue, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
|
||||||
use graphene_std::wasm_application_io::WasmApplicationIo;
|
use graphene_std::wasm_application_io::WasmApplicationIo;
|
||||||
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
||||||
@@ -180,7 +179,7 @@ fn compile_graph(document_string: String, application_io: Arc<WasmApplicationIo>
|
|||||||
let mut network = load_network(&document_string);
|
let mut network = load_network(&document_string);
|
||||||
fix_nodes(&mut network);
|
fix_nodes(&mut network);
|
||||||
|
|
||||||
let substitutions: std::collections::HashMap<String, DocumentNode> = preprocessor::generate_node_substitutions();
|
let substitutions = preprocessor::generate_node_substitutions();
|
||||||
preprocessor::expand_network(&mut network, &substitutions);
|
preprocessor::expand_network(&mut network, &substitutions);
|
||||||
|
|
||||||
let mut wrapped_network = wrap_network_in_scope(network, Arc::new(FontCache::default()), EditorMetadata::default(), application_io);
|
let mut wrapped_network = wrap_network_in_scope(network, Arc::new(FontCache::default()), EditorMetadata::default(), application_io);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ pub use graph_craft::proto::{Any, NodeContainer, TypeErasedBox, TypeErasedNode};
|
|||||||
use graph_craft::proto::{DynFuture, FutureAny, SharedNodeContainer};
|
use graph_craft::proto::{DynFuture, FutureAny, SharedNodeContainer};
|
||||||
use graphene_core::Context;
|
use graphene_core::Context;
|
||||||
use graphene_core::ContextDependencies;
|
use graphene_core::ContextDependencies;
|
||||||
use graphene_core::EditorContext;
|
|
||||||
use graphene_core::NodeIO;
|
use graphene_core::NodeIO;
|
||||||
use graphene_core::OwnedContextImpl;
|
use graphene_core::OwnedContextImpl;
|
||||||
use graphene_core::WasmNotSend;
|
use graphene_core::WasmNotSend;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ fn update_executor<M: Measurement>(name: &str, c: &mut BenchmarkGroup<M>) {
|
|||||||
c.bench_function(name, |b| {
|
c.bench_function(name, |b| {
|
||||||
b.iter_batched(
|
b.iter_batched(
|
||||||
|| (executor.clone(), proto_network.clone()),
|
|| (executor.clone(), proto_network.clone()),
|
||||||
|(mut executor, network)| futures::executor::block_on(executor.update(black_box(network, None))),
|
|(mut executor, network)| futures::executor::block_on(executor.update(black_box(network), None)),
|
||||||
criterion::BatchSize::SmallInput,
|
criterion::BatchSize::SmallInput,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -33,7 +33,7 @@ fn run_once<M: Measurement>(name: &str, c: &mut BenchmarkGroup<M>) {
|
|||||||
let proto_network = network.compile().unwrap().0;
|
let proto_network = network.compile().unwrap().0;
|
||||||
|
|
||||||
let executor = futures::executor::block_on(DynamicExecutor::new(proto_network)).unwrap();
|
let executor = futures::executor::block_on(DynamicExecutor::new(proto_network)).unwrap();
|
||||||
let context = graphene_std::any::EditorContext::default();
|
let context = graphene_std::EditorContext::default();
|
||||||
|
|
||||||
c.bench_function(name, |b| b.iter(|| futures::executor::block_on((&executor).evaluate_from_node(context.clone(), None))));
|
c.bench_function(name, |b| b.iter(|| futures::executor::block_on((&executor).evaluate_from_node(context.clone(), None))));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ fn update_executor(c: &mut Criterion) {
|
|||||||
let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap();
|
let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap();
|
||||||
(executor, proto_network)
|
(executor, proto_network)
|
||||||
},
|
},
|
||||||
|(mut executor, network)| futures::executor::block_on(executor.update(criterion::black_box(network, None))),
|
|(mut executor, network)| futures::executor::block_on(executor.update(criterion::black_box(network), None)),
|
||||||
criterion::BatchSize::SmallInput,
|
criterion::BatchSize::SmallInput,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user