Expand description
The testing harness (blueprint §9.1’s init_testing).
use astrs_node_api::prelude::*;
use astrs_wire::StopCause;
let mut harness = Node::init_testing()?;
let id = harness.node.id().clone();
harness.daemon.stop(&id, StopCause::Requested)?;
let event = harness.events.recv().expect("the stop");
assert!(event.is_stop());§What makes this worth having
A node’s logic is event in → output out, and everything between is the
session. A harness that stubbed the session would test the stub. This one
runs the real session — the real greeting, the real frame codec, the real
dispatcher, the real queues — against a MockDaemon that speaks the real
protocol on the other end of a tokio::io::duplex pair. The only thing
that is not real is the socket.
That buys three things a stub cannot:
- Two-node tests.
TestHarness::pairconnects a producer and a consumer wired to each other, so a service round trip or an action FSM is an ordinary#[test]. - Protocol regressions. A change that breaks the wire breaks these tests, because they are on the wire.
- Route-upgrade tests.
MockDaemon::upgrade_routedrives the §6.3 handshake, including the ack the node sends back.
Re-exports§
pub use daemon::UnixEndpoint;Unix pub use daemon::DUPLEX_BUFFER;pub use daemon::HANDSHAKE_TIMEOUT;pub use daemon::MockDaemon;pub use daemon::RecordedRequest;pub use daemon::RecordedSend;
Modules§
- daemon
MockDaemon— the daemon side of §7.3, in this process.
Structs§
- Test
Harness - A node, its event stream, and the daemon it is talking to.
Constants§
- DEFAULT_
WAIT - How long the harness’s convenience waits allow.