Skip to main content

Live

TestApp::start_live runs the same test body against a real stream file in a temp directory; no server is needed.

It connects the broker through its ordinary connect, so the file is created, written and read by the file client. The body is the one an in-process test runs; only the start call differs. A publish, settle and advance wait on the real clock until every subscription has handled what was published to it, ten seconds at most. start_live_within sets another bound. The file is the whole stand, so a live test runs on any machine, in the same cargo test as the rest. Each run takes a path of its own, so nothing an earlier run appended is read, and removes the file at the end.

The live mode is for what the log in memory leaves out: the bytes of a .ss file, what a file keeps across two runs of a service, and a file that existing_only refuses. Two runs on one path show a service resuming at a stored position, or reading again what it acknowledged. A stdio stage is tested live as a child process with piped standard input and output, because a stdio broker in a test process would take that process's own pipes.

Example​

The two tests share one body: one in process, one on a stream file of the run's own.

/// The body both modes run; only the start call differs.
async fn confirms_an_order(tb: TestApp<()>) -> Result<(), Box<dyn Error>> {
tb.broker::<FileBroker>()
.message(&Order { id: 7 })
.publish()
.await?;

tb.broker::<FileBroker>()
.subscriber("orders")
.assert_called_once()
.with(&Order { id: 7 });
tb.broker::<FileBroker>()
.published::<Receipt>("receipts")
.assert_called_once()
.with(&Receipt { order: 7 });
tb.shutdown().await?;
Ok(())
}

#[tokio::test]
async fn in_process() -> Result<(), Box<dyn Error>> {
confirms_an_order(TestApp::start(app("/var/lib/shop/orders.ss")).await?).await
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn on_a_stream_file() -> Result<(), Box<dyn Error>> {
// A file of this run's own, so nothing an earlier run appended is read.
let path = env::temp_dir().join(format!("ruststream-sea-file-live-{}.ss", process::id()));
let path = path.to_string_lossy().into_owned();

confirms_an_order(TestApp::start_live(app(&path)).await?).await?;
fs::remove_file(&path)?;
Ok(())
}