Skip to main content

Crate ulo_rpc_conformance

Crate ulo_rpc_conformance 

Source
Expand description

§ulo-rpc-conformance

The conformance suite every ulo-rpc link runs. A link is the transport under ulo-rpc’s client and server: TCP, UDP, a broker, or one written outside the ulo repository. One macro stamps the suite’s scenarios as #[test]s against the link: requests and replies, events, the four call shapes, cancellation, deadlines, drain, recovery from a dropped connection, two instances on one pattern and admission under load. A link whose tests/conformance.rs passes keeps the same promises as the links ulo ships, each of which runs the suite in CI.

§Install

The suite is a dev-dependency of the link crate. The example below runs it against ulo-rpc-tcp, which stands in for your link:

[dev-dependencies]
ulo = "=0.1.0-alpha.3"
ulo-rpc-conformance = { version = "=0.1.0-alpha.3", features = ["tokio"] }
ulo-rpc-tcp = "=0.1.0-alpha.3"

Each crate is pinned with =, since a caret on a pre-release also takes a later alpha, which may break this one. tokio brings OnTokio, the runtime half of a link built on tokio; a link on smol enables smol and names OnSmol instead.

§First run

tests/conformance.rs:

use std::net::{Ipv4Addr, SocketAddr};

use ulo::BoundAddr;
use ulo_rpc_conformance::relay::Relay;
use ulo_rpc_conformance::{Broker, OnTokio, startup_failed};
use ulo_rpc_tcp::Tcp;

/// One scenario's environment: a server on a port of its own, the client reaching it through a
/// relay that `disrupt` cuts.
struct Loopback {
    relay: Relay,
}

impl Broker for Loopback {
    type Harness = OnTokio;
    type Link = Tcp;

    async fn start() -> Self {
        Loopback { relay: Relay::without_upstream().await }
    }

    /// The server's link, on port 0: the OS chooses the port as the server binds.
    fn link(&self) -> Tcp {
        Tcp::new(SocketAddr::from((Ipv4Addr::LOCALHOST, 0)))
    }

    /// The client's link, through the relay, aimed at the address the server bound.
    fn client_link(&self, server: &[BoundAddr]) -> Tcp {
        let [bound] = server else { startup_failed!("expected one bound server address, got {server:?}") };
        self.relay.forward_to(bound.addr);
        Tcp::new(self.relay.addr())
    }

    async fn disrupt(&self) {
        self.relay.cut().await;
    }

    async fn client_connections(&self) -> Option<usize> {
        Some(self.relay.open().await)
    }
}

ulo_rpc_conformance::conformance_suite!(Loopback; not_applicable {
    a_late_opened_releases_the_held_cancel: "a request and its control frames share one ordered lane, so the link holds no `cancel` for an `opened`",
    a_held_cancel_is_dropped_when_its_hold_runs_out: "a request and its control frames share one ordered lane, so the link holds no `cancel` for an `opened`",
    a_held_cancel_lasts_until_its_call_s_deadline: "a request and its control frames share one ordered lane, so the link holds no `cancel` for an `opened`",
});

cargo test --test conformance runs every scenario as a test of its own, named after the scenario, and reports the three declared above as ignored with their reasons.

Your link takes Tcp’s place. start answers an environment no other scenario shares: a fresh broker or namespace, or nothing where the server binds port 0. link answers the server’s link, client_link the client’s once the servers are bound, and disrupt severs the client’s connection. A link run against a broker in a container starts it in start, through relay::unshadowed when the container’s port is published on the host, and fails a start that does not come up through startup_failed!. The suite depends on no container library; the link’s own dev-dependencies bring one.

community-link is a complete link written as a crate outside the workspace would write it, against ulo-rpc’s public link API alone, with its tests/conformance.rs run in CI.

A link’s Capabilities hold every ability unless the link declares one absent with without_<ability>(reason). A link that declares nothing is held to every scenario, and fails the ones it cannot keep. A declared absence changes what the scenarios assert: a scenario whose ability is absent asserts the refusal the declaration names, or, where it cannot run without the ability, is skipped with one line naming the scenario, the ability and the reason on standard error.

not_applicable { scenario: "reason" } is for a scenario no capability describes, such as the held-cancel scenarios above on a link that holds no cancel. The test is stamped #[ignore = "<reason>"], a name that is no scenario fails to compile, and cargo test -- --ignored runs it, where it fails. A link that does hold a cancel until the server’s opened declares the same three not applicable too: they read the link’s client table through a probe outside the suite’s public API, which the links ulo ships attach.

§Scenarios

The scenarios are the functions of the cases modules, each documented with what it asserts.

§Will it work for me

  • Rust 1.88 or later.
  • Runtimes: the suite names none. tokio and smol bring the two harnesses; another runtime implements Harness.
  • Parallelism: the scenarios run in parallel under libtest. Broker::PARALLEL bounds how many hold an environment at once, and a host short of memory sets ULO_CONFORMANCE_PARALLEL to a positive integer; the smaller of the two applies.
  • Startup failures are written to a file before the test panics: under $ULO_CONFORMANCE_FAILURES when it is set, otherwise under conformance-failures in the target directory the test binary was built into.
  • Stability: the scenarios, Broker, Harness and conformance_suite! are the contract a link is held to. While the version is a pre-release, every ulo crate releases at one version and a pre-release may change any of them. From 0.1.0 on, a release that adds or tightens a scenario or changes the contract is a minor release, 0.1 to 0.2, since a link that passed the earlier suite can fail it.

§Where to go next

§License

MIT.

§What the scenarios assert

A scenario asserts kinds and reason strings, never message text, with one exception: the spent-cap scenario compares the shutdown phrase, through the ulo_transport::SHUTDOWN_MESSAGE constant and never a literal, the only thing telling the server’s unavailable from the client’s own for a connection that closed. A scenario a link’s capabilities exclude asserts the refusal the capability declares instead: a streamed shape on UDP is refused at startup, and the scenarios below the server that open a streamed request are declared not applicable there, a binary payload on a JSON link before any I/O and its handler at startup, a miss on a link without miss_signal is the client’s Timeout, the two-instance scenarios run one instance on an Addressed link, where a second cannot share the address, a request runs on both instances on a link without single_delivery, and an event declared every_instance is refused at startup on a link without every_instance. A scenario that needs a capability to run at all, cancel_follows_its_request on ordered_control and an_event_reaches_one_instance on single_delivery, is skipped on a link declared without it, writing the declared reason to standard error through skipped.

No scenario passes on silence. The client’s own Timeout passes only where it is the declared answer: a scenario about the client’s timeout or deadline-ms, a call nothing takes on a link without miss_signal, a call reaching a draining server on a link that declares unserved_hold, where an event emitted then has to reach the next instance, and a call sent during the drain on a link declared without confirmed_drain, where a call sent once the server has closed has to be refused Unavailable; a link that does not declare it is held to the confirmed drain. A scenario that cannot apply to a link is declared not applicable in conformance_suite! and reported as ignored; run on that link, it fails.

§Runtimes

The suite names no runtime. A broker’s Harness is its runtime half, as the HTTP and runtime suites’ are: the app’s runtime, which every server and client in a scenario runs on and every wait and task of the scenario’s own goes through, and a block_on each scenario runs inside, beside a one-thread block_on for the scenario that shows a link’s connect does not stall its thread. OnTokio, behind the tokio feature, is the harness of every link built on tokio; OnSmol, behind smol, runs the scenarios on an async-executor Executor. The relay runs on threads of its own, on std sockets, so it carries a link on either.

A host short of memory bounds how many scenarios hold an environment at once by setting PARALLEL_VAR, ULO_CONFORMANCE_PARALLEL, to a positive integer: the bound is the smaller of it and the broker’s own Broker::PARALLEL, or it alone when the broker declares none. Unset or empty, it bounds nothing, and libtest’s --test-threads still applies on top of either.

ULO_CONFORMANCE_PARALLEL=6 cargo test -p ulo-rpc-rabbitmq --features integration --test conformance

Re-exports§

pub use cases::deadlines::Stamped;

Modules§

cases
The scenario list of transports DESIGN §5.2, one module per group, each scenario generic over the Broker under test.
relay
A TCP relay a suite’s environment puts between a client and what it reaches, so a disrupt can sever the client’s connections and nothing else: the server keeps its own, and the relay keeps accepting, so the client’s next connection goes through, at once or after an outage the environment chooses.

Macros§

conformance_suite
Stamps every scenario as a #[test] for the broker type $broker, each running its scenario through the broker’s Harness::block_on.
startup_failed
Fails a scenario whose environment did not start, as panic! with the same arguments would, after writing the message to a file of its own under failures_dir; the panic names the file. Every startup path in a suite fails through it, and a suite’s environment implementation’s own startup should too.

Structs§

Budget
How long a scenario waits on its environment.
Slots
The slots one stamped suite’s scenarios share. A suite’s stamping macro declares one as a static beside the tests it writes, and each test holds a slot from before its environment starts until the scenario has returned; an environment or link author names it nowhere. Each scenario runs on its own test thread, so a slot is waited for by blocking that thread before the scenario’s runtime starts.

Constants§

PARALLEL_VAR
The environment variable through which a host bounds how many scenarios of one suite hold an environment at once. A value that is not a positive integer fails every scenario through startup_failed!.

Traits§

Broker
One link’s environment for the suite: a broker, or, for TCP and UDP, the server’s own socket, bound at port 0 and read back.
Harness
The runtime a suite’s scenarios run on, as the suite drives it: the app’s runtime and the executor each scenario is run to its end on.

Functions§

failures_dir
Where startup failures are written: $ULO_CONFORMANCE_FAILURES when it is set, otherwise conformance-failures in the target directory the running test binary was built into, read off the binary’s path, <target>/<profile>/deps/<binary>: target/conformance-failures at the root of a workspace built into its default target directory. A binary whose own directory is not a deps directory writes beside itself.
report
error and every source under it, joined by : , for a failure message: a scenario that fails while its environment starts says what failed, the broker’s container, the server’s bind or the client’s connect, and why. A source whose text the message already carries is not repeated.
skipped
Skips a scenario whose host or link declares the capability it needs absent: writes one line naming the scenario, the capability and the declared reason to the process’s standard error, which libtest does not capture, so the line is in the run’s output whether the test passes or fails. The scenario then returns, and libtest counts it as passed.
startup_failed
The function startup_failed! expands to: writes message under failures_dir, then panics with it and the file’s path, at the caller’s location.