From 3e2146b5a1254f3ca64492a0de791ebdfa9ce17b Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Sun, 4 Oct 2026 11:53:05 +0300 Subject: [PATCH] test: wait for TinyDocs module idle state Co-authored-by: Medulla --- crates/tinydocs-module/tests/module_e2e.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/tinydocs-module/tests/module_e2e.rs b/crates/tinydocs-module/tests/module_e2e.rs index 0cf4daa..7b75bc4 100644 --- a/crates/tinydocs-module/tests/module_e2e.rs +++ b/crates/tinydocs-module/tests/module_e2e.rs @@ -51,7 +51,7 @@ async fn the_built_module_serves_every_format_over_a_real_broker() { extracts_and_renders_document_intake(&client, &target, &proxy).await; refuses_a_stream_that_contradicts_the_spec(&client, &target).await; - assert!(matches!(modules.list()[0].state, ModuleState::Ready)); + wait_until_idle(&modules).await; broker_task.abort(); } @@ -129,6 +129,24 @@ async fn wait_until_serving(client: &Connection) { .expect("module should become ready"); } +/// A call reply can reach its caller just before the host retires its in-flight +/// count. Accept that valid `Serving` snapshot briefly, but fail immediately if +/// the module faulted or stopped and require it to settle back to `Ready`. +async fn wait_until_idle(modules: &ModuleHost) { + tokio::time::timeout(Duration::from_secs(5), async { + loop { + let state = modules.list()[0].state.clone(); + match state { + ModuleState::Ready => return, + ModuleState::Serving => tokio::task::yield_now().await, + other => panic!("module left service after E2E calls: {other:?}"), + } + } + }) + .await + .expect("module should finish serving the final call"); +} + /// No inbound payload, a held document out. async fn generates_a_docx(proxy: &tinybus::Proxy) { let handle: OutputRef = proxy