Skip to content

Commit

Permalink
fix runtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjoehnk committed Jul 11, 2024
1 parent 91a3c63 commit 34fc222
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 64 deletions.
6 changes: 3 additions & 3 deletions crates/runtime/pipeline/nodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ macro_rules! node_impl {
pub fn list_ports(&self, injector: &Injector) -> Vec<(PortId, PortMetadata)> {
match self {
$(Node::$node_type(node) => node.list_ports(injector),)*
Node::TestSink(_) => vec![],
Node::TestSink(node) => node.list_ports(injector),
}
}

pub fn settings(&self, injector: &Injector) -> Vec<NodeSetting> {
match self {
$(Node::$node_type(node) => node.settings(injector),)*
Node::TestSink(_) => vec![],
Node::TestSink(node) => node.settings(injector),
}
}

pub fn update_setting(&mut self, setting: NodeSetting) -> anyhow::Result<()> {
match self {
$(Node::$node_type(node) => node.update_setting(setting),)*
Node::TestSink(_) => Ok(()),
Node::TestSink(node) => node.update_setting(setting),
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/runtime/src/commands/add_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ impl<'a> Command<'a> for AddLinkCommand {

fn apply(&self, pipeline: &mut Pipeline) -> anyhow::Result<(Self::Result, Self::State)> {
let mut state = None;
if pipeline.get_node_dyn(&self.link.target).is_none() {
return Err(anyhow::anyhow!("Target node does not exist"));
}
let metadata = pipeline
.try_get_input_port_metadata(&self.link.target, &self.link.target_port)
.ok_or_else(|| anyhow::anyhow!("Target port does not exist"))?;
Expand Down
50 changes: 15 additions & 35 deletions crates/runtime/src/commands/delete_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,26 @@ impl DeleteNodesCommand {
#[cfg(test)]
mod tests {
use crate::commands::DeleteNodesCommand;
use crate::pipeline_access::PipelineAccess;
use crate::pipeline::Pipeline;
use mizer_commander::Command;
use mizer_layouts::{
ControlConfig, ControlDecorations, ControlPosition, ControlSize, ControlType, Layout,
LayoutStorage,
};
use mizer_node::*;
use mizer_nodes::FaderNode;
use mizer_ports::PortType;
use pinboard::NonEmptyPinboard;

#[test]
fn delete_node_should_remove_the_connected_links() {
let mut pipeline_access = PipelineAccess::new();
let mut planner = ExecutionPlanner::new();
let injector = Injector::new();
let mut pipeline = Pipeline::new();
let layout_storage = LayoutStorage::new(NonEmptyPinboard::new(Default::default()));
let path1 = NodePath("/node1".into());
let path2 = NodePath("/node2".into());
pipeline_access.internal_add_node(
path1.clone(),
FaderNode::default().into(),
Default::default(),
);
pipeline_access.internal_add_node(
path2.clone(),
FaderNode::default().into(),
Default::default(),
);
let injector = Injector::default();
let ports = pipeline_access.nodes[&path1].list_ports(&injector);
pipeline_access.ports.insert(path1.clone(), ports);
let ports = pipeline_access.nodes[&path2].list_ports(&injector);
pipeline_access.ports.insert(path2.clone(), ports);
pipeline_access
let node1 = pipeline.add_node(&injector, NodeType::Fader, Default::default(), Default::default(), Default::default()).unwrap();
let node2 = pipeline.add_node(&injector, NodeType::Fader, Default::default(), Default::default(), Default::default()).unwrap();
let path1 = node1.path;
let path2 = node2.path;
pipeline
.add_link(NodeLink {
source: path1.clone(),
source_port: "Output".into(),
Expand All @@ -161,24 +147,19 @@ mod tests {
.unwrap();
let cmd = DeleteNodesCommand { paths: vec![path1] };

cmd.apply((&mut pipeline_access, &mut planner, &layout_storage))
.unwrap();
cmd.apply((&mut pipeline, &layout_storage)).unwrap();

let links = pipeline_access.links.read();
let links = pipeline.list_links().collect::<Vec<_>>();
assert!(links.is_empty());
}

#[test]
fn delete_node_should_remove_layout_controls() {
let mut pipeline_access = PipelineAccess::new();
let mut planner = ExecutionPlanner::new();
let injector = Injector::new();
let mut pipeline = Pipeline::new();
let layout_storage = LayoutStorage::new(NonEmptyPinboard::new(Default::default()));
let path = NodePath("/node".into());
pipeline_access.internal_add_node(
path.clone(),
FaderNode::default().into(),
Default::default(),
);
let descriptor = pipeline.add_node(&injector, NodeType::Fader, Default::default(), Default::default(), Default::default()).unwrap();
let path = descriptor.path;
let mut layouts = layout_storage.read();
layouts.push(Layout {
id: "".into(),
Expand All @@ -198,8 +179,7 @@ mod tests {
layout_storage.set(layouts);
let cmd = DeleteNodesCommand { paths: vec![path] };

cmd.apply((&mut pipeline_access, &mut planner, &layout_storage))
.unwrap();
cmd.apply((&mut pipeline, &layout_storage)).unwrap();

let layouts = layout_storage.read();
assert!(layouts[0].controls.is_empty());
Expand Down
25 changes: 6 additions & 19 deletions crates/runtime/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,28 +373,15 @@ mod tests {
#[test]
fn node_runner_should_lend_state_ref() {
let mut runner = CoordinatorRuntime::new();
let node = FaderNode::default();
let path = NodePath("/test".to_string());
runner
.injector
.get_mut::<PipelineAccess>()
.unwrap()
.internal_add_node(path.clone(), node.into(), Default::default());
runner
.injector
.get_mut::<ExecutionPlanner>()
.unwrap()
.add_node(ExecutionNode {
path: path.clone(),
attached_executor: None,
});
runner.plan();
let mut pipeline = Pipeline::new();
let node = pipeline.add_node(runner.injector(), NodeType::Fader, Default::default(), Default::default(), Default::default()).unwrap();
runner.injector.provide(pipeline);

runner.process();

let state = runner
.pipeline
.get_state::<<FaderNode as ProcessingNode>::State>(&path)
let pipeline = runner.injector.inject::<Pipeline>();
let state = pipeline
.read_state::<<FaderNode as ProcessingNode>::State>(&node.path)
.unwrap();
assert_eq!(state, &0f64);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use mizer_pipeline::NodePreviewRef;
pub use node_metadata::NodeMetadataRef;

pub use self::api::*;
pub use self::pipeline::Pipeline;
pub use self::pipeline::*;
pub use self::coordinator::CoordinatorRuntime;
pub use self::views::LayoutsView;

Expand Down
1 change: 0 additions & 1 deletion crates/runtime/tests/basic_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fn main() {
sink.clone(),
"Value",
);
runtime.plan();

run_for_one_second(runtime);

Expand Down
1 change: 0 additions & 1 deletion crates/runtime/tests/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn run_pipeline_with_node<N: Into<Node> + ProcessingNode + 'static>(
sink.clone(),
port,
);
runtime.plan();

for _ in 0..frames {
runtime.process();
Expand Down
1 change: 0 additions & 1 deletion crates/runtime/tests/snapshots/basic_pipeline__main.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ expression: frames
0.02829598769909014,
0.01359588658074451,
0.004182421399140213,
0.00015790535835014108,
]
1 change: 0 additions & 1 deletion crates/runtime/tests/snapshots/nodes__oscillator.snap
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ expression: frames
0.02829598769909014,
0.01359588658074451,
0.004182421399140213,
0.00015790535835014108,
]
6 changes: 4 additions & 2 deletions crates/runtime/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use mizer_nodes::test_sink::TestSink;
use mizer_nodes::Node;
use mizer_ports::{PortId, PortType};
use mizer_runtime::commands::{AddLinkCommand, AddNodeCommand, StaticNodeDescriptor};
use mizer_runtime::CoordinatorRuntime;
use mizer_runtime::{CoordinatorRuntime, Pipeline, RuntimeProcessor};
pub use mizer_util::clock::*;

pub fn run_node(
Expand All @@ -15,6 +15,8 @@ pub fn run_node(
sink: TestSink,
source_port: impl Into<PortId>,
) {
runtime.provide(Pipeline::new());
runtime.add_processor(RuntimeProcessor);
let output_path = setup_sink(sink, runtime.injector_mut());
let oscillator_node = add_node_command(node_type, node, runtime.injector_mut());
add_link(
Expand Down Expand Up @@ -42,7 +44,7 @@ fn add_node_command(
}

fn add_link(
source_port: impl Into<PortId> + Sized,
source_port: impl Into<PortId>,
oscillator_node: StaticNodeDescriptor,
output_path: NodePath,
injector: &mut Injector,
Expand Down

0 comments on commit 34fc222

Please sign in to comment.