Skip to main content

run_node_contract_tests

Macro run_node_contract_tests 

Source
macro_rules! run_node_contract_tests {
    ($mod_name:ident, {
            make_nodelink: $make_nodelink:expr
        }) => { ... };
}
Expand description

Expand a canonical suite of node contract tests for a NodeLink factory.

§Purpose

Generate a focused #[test] module that runs the standard Node contract fixtures (lifecycle, single-message, and batched behaviour, error/backpressure mapping, and wrapper-specific checks for Source, Sink, and Model).

§Required argument

  • make_nodelink: || -> NodeLink<N, IN, OUT, InP, OutP> A zero-argument closure that returns a fresh NodeLink owning the concrete node under test. The closure is invoked once per generated test (i.e., the factory must return a new, independent NodeLink each time).

§Type requirements

  • The node produced by your NodeLink must implement Node<IN, OUT, InP, OutP>.
  • Payload types InP and OutP must implement Payload + Default + Clone so the tests can synthesize Message::new(header, P::default()) values.

§Behaviour

The macro expands to a mod $mod_name { ... } containing these tests:

  • initialize_start_stop_roundtrip
  • process_message_enqueues_and_made_progress
  • step_on_empty_returns_noinput
  • step_pops_and_calls_process_message
  • step_batch_respects_fixed_n_disjoint
  • step_batch_respects_sliding_window
  • step_maps_backpressure_and_errors
  • source_specific_behaviour
  • sink_specific_behaviour
  • model_specific_batching_behaviour
  • fixed_n_with_max_delta_t_behaviour

Each generated test delegates to a fixture in node::contract_tests. The suite is adaptive: fixtures will skip or adjust assertions for IN == 0 (sources), OUT == 0 (sinks), or when the node reports NodeKind::Source, NodeKind::Sink, or NodeKind::Model.

§Usage

use limen_core::run_node_contract_tests;

run_node_contract_tests!(my_node_contracts, {
    make_nodelink: || create_my_node_link()
});

Put the macro invocation in your crate’s tests (or #[cfg(test)] module). Keep the make_nodelink factory cheap and deterministic so the per-test instances are reliable.

§Notes

  • Tests assert node-level semantics (counts, StepResult, telemetry) and do not inspect payload internals. Implementors should ensure payloads derive/implement Default + Clone for compatibility with the suite.