Skip to main content

Module testing

Module testing 

Source
Available on crate feature testing only.
Expand description

A harness for driving both engines against each other, on a virtual clock.

Because the sessions are deterministic and take now as a parameter, a whole conversation — handshake, control-type selection, a description, an instruction, a lost acknowledgement, a timer expiring — is an ordinary unit test that runs in microseconds. Conversation wires a RmSession and a CemSession back to back through an in-memory pipe and records everything that crosses it.

Every message crosses the wire format on the way, so what is under test is the encoding as well as the logic.

use s2_kit::prelude::*;
use s2_kit::testing::Conversation;

let mut c = Conversation::battery();
c.open();
assert!(matches!(c.cem.state(), SessionState::Connected));
assert!(c.cem.details().is_some(), "the resource described itself");

Structs§

Conversation
A Resource Manager and a Customer Energy Manager, talking to each other.
ReplayReport
What a replay found, and what it saw.
TranscriptEntry
One line of a .s2log transcript.

Enums§

Direction
Which way a message went.
Finding
Something a recorded conversation did that this crate would not have done.

Functions§

battery_details
The 20 kWh home battery from s2-example-implementations.
battery_system
A battery’s system description: charge, idle and discharge over a 0–100 % store.
charge
An FRBC instruction for the battery fixture.
every_message
One of every message, with every optional field set.
pv_constraints
The PV installation’s constraints: curtail freely between −4 kW and zero.
pv_details
The 2 kWp curtailable PV installation from s2-example-implementations.
read_s2log
Read a whole .s2log, skipping anything that is not a transcript line.
replay
Replay a recorded conversation and say where it departs from the standard.
replay_with
As replay, with the observer configured — a different wire profile, strict decoding, an S2 Connect session where a handshake would be redundant.