Fix flakiness in WebSocket tests (#9169)

The connection was being added to the list after the WebSocket response
was sent.

So the test can sometimes race and observe connections before the list
was updated.

After this change, connection and request is added to the list before
the response is sent.
This commit is contained in:
pakrym-oai 2026-01-13 15:09:59 -08:00 committed by GitHub
parent 89403c5e11
commit 9f8d3c14ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -821,13 +821,20 @@ pub async fn start_websocket_server(connections: Vec<Vec<Vec<Value>>>) -> WebSoc
continue;
};
let mut connection_log = Vec::new();
let connection_index = {
let mut log = requests.lock().unwrap();
log.push(Vec::new());
log.len() - 1
};
for request_events in connection_requests {
let Some(Ok(message)) = ws_stream.next().await else {
break;
};
if let Some(body) = parse_ws_request_body(message) {
connection_log.push(WebSocketRequest { body });
let mut log = requests.lock().unwrap();
if let Some(connection_log) = log.get_mut(connection_index) {
connection_log.push(WebSocketRequest { body });
}
}
for event in &request_events {
@ -840,7 +847,6 @@ pub async fn start_websocket_server(connections: Vec<Vec<Vec<Value>>>) -> WebSoc
}
}
requests.lock().unwrap().push(connection_log);
let _ = ws_stream.close(None).await;
if connections.lock().unwrap().is_empty() {