SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Control server: make the timed-out request test deterministic (#2388) (#2391)
Martin Pålsson2b8e85a7c60b
diff --git a/apps/solidcraft/src/control_server.rs b/apps/solidcraft/src/control_server.rsindex 8680d0cd15..c7ee296adf 100644--- a/apps/solidcraft/src/control_server.rs+++ b/apps/solidcraft/src/control_server.rs@@ -292,13 +292,16 @@ mod tests {let listener = TcpListener::bind("127.0.0.1:0").unwrap();let addr = listener.local_addr().unwrap();let (tx, rx) = channel::<ControlRequest>();+ // The slow request is held until the test has seen it time out, so the test does not+ // race the clock on a loaded machine.+ let (gate_tx, gate_rx) = channel::<()>();let ran = std::sync::Arc::new(std::sync::Mutex::new(Vec::<String>::new()));let seen = ran.clone();std::thread::spawn(move || {for req in rx {seen.lock().unwrap().push(req.method.clone());if req.method == "slow" {- std::thread::sleep(Duration::from_millis(400));+ let _ = gate_rx.recv();}let _ = req.reply.send(json!({"ok": true, "result": req.method}));}@@ -325,8 +328,15 @@ mod tests {assert!(r["busy"] == true && r["id"] == 2, "{r}");let r = ask(json!({"id": 3, "method": "control.pending"}));assert_eq!((&r["result"]["pending"], &r["result"]["done"]), (&json!(1), &json!(false)), "{r}");- std::thread::sleep(Duration::from_millis(600));- let r = ask(json!({"id": 4, "method": "control.pending"}));+ gate_tx.send(()).unwrap();+ let deadline = std::time::Instant::now() + Duration::from_secs(10);+ let r = loop {+ let r = ask(json!({"id": 4, "method": "control.pending"}));+ if r["result"]["done"] == true || std::time::Instant::now() > deadline {+ break r;+ }+ std::thread::sleep(Duration::from_millis(10));+ };assert_eq!((&r["result"]["pending"], &r["result"]["done"], &r["result"]["reply"]["result"]),(&json!(1), &json!(true), &json!("slow")),