Skip to content

Commit 56d3f72

Browse files
committed
test(websocket): gate the bind/debug/ignore specs on the response arriving
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.
1 parent 311bcf8 commit 56d3f72

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

spec/websocket/session_spec.cr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module PlaceOS::Api::WebSocket
6565
status_name = "nugget"
6666

6767
id = rand(10).to_i64
68-
results = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod|
68+
results = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates|
6969
request = {
7070
id: id,
7171
system_id: control_system.id.as(String),
@@ -74,9 +74,9 @@ module PlaceOS::Api::WebSocket
7474
command: Session::Request::Command::Bind,
7575
}
7676
ws.send Session::Request.new(**request).to_json
77-
sleep 100.milliseconds
77+
wait_for_updates(updates, 1)
7878
ws.send Session::Request.new(**request.merge({command: Session::Request::Command::Bind})).to_json
79-
sleep 100.milliseconds
79+
wait_for_updates(updates, 2)
8080
end
8181

8282
updates, control_system, mod = results
@@ -121,7 +121,7 @@ module PlaceOS::Api::WebSocket
121121
status_name = "nugget"
122122

123123
id = rand(10).to_i64
124-
updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod|
124+
updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates|
125125
request = {
126126
id: id,
127127
system_id: control_system.id.as(String),
@@ -130,7 +130,7 @@ module PlaceOS::Api::WebSocket
130130
command: Session::Request::Command::Debug,
131131
}
132132
ws.send Session::Request.new(**request).to_json
133-
sleep 100.milliseconds
133+
wait_for_updates(updates, 1)
134134
end
135135

136136
# Check all messages received
@@ -143,7 +143,7 @@ module PlaceOS::Api::WebSocket
143143
status_name = "nugget"
144144

145145
id = rand(10).to_i64
146-
updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod|
146+
updates, _, _ = test_websocket_api(Systems.base_route, Spec::Authentication.headers) do |ws, control_system, mod, updates|
147147
request = {
148148
id: id,
149149
system_id: control_system.id.as(String),
@@ -152,7 +152,7 @@ module PlaceOS::Api::WebSocket
152152
command: Session::Request::Command::Ignore,
153153
}
154154
ws.send Session::Request.new(**request).to_json
155-
sleep 100.milliseconds
155+
wait_for_updates(updates, 1)
156156
end
157157

158158
# Check all messages received

0 commit comments

Comments
 (0)