The guide's first deliverable is one small program with a counter RPC, a pub/sub
observer and a frame artifact held past its message object. examples/demo.rs was
already that; its body moves into run(), which returns the lines it prints, so
tests/example_demo.rs can assert all seven of them. The counter now uses the
spec's own example.counter / Counter.Increment / {"amount": 1} and pins the
registration it discovered, and the example prints the router's root count while
the frame is held and after the last handle goes, so the lifetime it
demonstrates is visible rather than implied. cargo run -p flybus --example demo
prints the same lines.
tests/perf.rs reports what BUS-03 and bus-v1 section 11.7 actually ask for.
Allocate, the producer's copy into staging, the router's seal copy, publish
admission, the RPC round trip and a consumer's readback are six separate
percentile lines instead of one. The router gets its own two-thread runtime
whose threads carry a distinct name, and per-thread CPU is sampled from /proc by
that name, so router CPU is separable from the clients' in the same process.
Store bytes, outstanding roots and queue lengths are reported live as well as
peak.
26 lines
1.1 KiB
Rust
26 lines
1.1 KiB
Rust
//! The guide's example is also a test: `cargo run -p flybus --example demo` prints exactly
|
|
//! these lines (bus-v1 section 11, implementation guide section 1).
|
|
|
|
#[allow(dead_code)]
|
|
#[path = "../examples/demo.rs"]
|
|
mod demo;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn the_example_shows_a_counter_rpc_an_observer_and_a_held_frame() {
|
|
let lines = demo::run().await.expect("the example ran");
|
|
assert_eq!(
|
|
lines.iter().map(String::as_str).collect::<Vec<_>>(),
|
|
vec![
|
|
// A counter service, called three times through the router.
|
|
"counter total = 1",
|
|
"counter total = 2",
|
|
"counter total = 3",
|
|
// One observer, one accepted publication, one sequence number.
|
|
"published sequence 1 to 1 subscriber(s)",
|
|
// 160x144 RGBA, read after the message object was dropped.
|
|
"read 92160 bytes after the message was dropped",
|
|
"while the frame is held: 1 artifact(s), 1 root(s)",
|
|
"after the last handle: 0 artifact(s), 0 root(s)",
|
|
]
|
|
);
|
|
}
|