From 56d3f7241dc007c4106fec226f1bc75c91fe414e Mon Sep 17 00:00:00 2001 From: Cameron Reeves Date: Thu, 6 Aug 2026 15:06:59 +1000 Subject: [PATCH] test(websocket): gate the bind/debug/ignore specs on the response arriving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These three sent a request, slept a fixed 100ms, then asserted on `updates.size`. That is a race, not a wait: under any extra load the response has not arrived yet and the spec fails with "expected 1, got 0" somewhere unrelated to whatever the branch actually changed. `wait_for_updates` already exists for exactly this, with a comment saying so, and the `receives updates` spec already uses it — these three were simply never converted. The helper polls to a 5s deadline and fails loudly on timeout, so a genuine regression still reports as one. Found while merging the Azure consent stack: the `debug` spec failed twice in a row on a branch that only touched the consent controller, while passing on master. Six extra examples were enough to tip it. --- spec/websocket/session_spec.cr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/websocket/session_spec.cr b/spec/websocket/session_spec.cr index b4f7ad33..cda2cd99 100644 --- a/spec/websocket/session_spec.cr +++ b/spec/websocket/session_spec.cr @@ -65,7 +65,7 @@ module PlaceOS::Api::WebSocket status_name = "nugget" id = rand(10).to_i64 - results = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod| + results = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates| request = { id: id, system_id: control_system.id.as(String), @@ -74,9 +74,9 @@ module PlaceOS::Api::WebSocket command: Session::Request::Command::Bind, } ws.send Session::Request.new(**request).to_json - sleep 100.milliseconds + wait_for_updates(updates, 1) ws.send Session::Request.new(**request.merge({command: Session::Request::Command::Bind})).to_json - sleep 100.milliseconds + wait_for_updates(updates, 2) end updates, control_system, mod = results @@ -121,7 +121,7 @@ module PlaceOS::Api::WebSocket status_name = "nugget" id = rand(10).to_i64 - updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod| + updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates| request = { id: id, system_id: control_system.id.as(String), @@ -130,7 +130,7 @@ module PlaceOS::Api::WebSocket command: Session::Request::Command::Debug, } ws.send Session::Request.new(**request).to_json - sleep 100.milliseconds + wait_for_updates(updates, 1) end # Check all messages received @@ -143,7 +143,7 @@ module PlaceOS::Api::WebSocket status_name = "nugget" id = rand(10).to_i64 - updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod| + updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates| request = { id: id, system_id: control_system.id.as(String), @@ -152,7 +152,7 @@ module PlaceOS::Api::WebSocket command: Session::Request::Command::Ignore, } ws.send Session::Request.new(**request).to_json - sleep 100.milliseconds + wait_for_updates(updates, 1) end # Check all messages received