Description
The test backend::inbound::ws::session::tests::closes_on_malformed_json intermittently fails in CI with:
thread 'inbound::ws::session::tests::closes_on_malformed_json' panicked at backend/src/inbound/ws/session_tests.rs:136:18: expected close frame, got Ping(b"")
Root Cause
The test assumes the next frame after sending malformed JSON will be a Close frame. However, the WebSocket session has a heartbeat mechanism that sends Ping frames at regular intervals. When timing aligns unfavorably, a Ping frame can arrive before the Close frame, causing the assertion to fail.
Current Code (lines 131-137)
let frame = socket.next().await.expect("response frame").expect("frame");
match frame {
Frame::Close(reason) => {
assert_eq!(reason.expect("reason").code, CloseCode::Policy);
}
other => panic!("expected close frame, got {other:?}"),
}
Suggested Fix
Follow the pattern used in closes_after_timeout_without_client_messages which correctly handles intermediate Ping/Pong frames by looping until a Close frame is received:
let frame = loop {
let frame = socket.next().await.expect("response frame").expect("frame");
match frame {
Frame::Ping(_) | Frame::Pong(_) => continue,
other => break other,
}
};
match frame {
Frame::Close(reason) => {
assert_eq!(reason.expect("reason").code, CloseCode::Policy);
}
other => panic!("expected close frame, got {other:?}"),
}
Reproduction
The failure is timing-dependent and occurs sporadically. It was observed during CI runs for PR #277 but passes on local rerun.
Location
- File: backend/src/inbound/ws/session_tests.rs:122-138
- Test: closes_on_malformed_json
Labels
bug, flaky-test, backend
Description
The test backend::inbound::ws::session::tests::closes_on_malformed_json intermittently fails in CI with:
thread 'inbound::ws::session::tests::closes_on_malformed_json' panicked at backend/src/inbound/ws/session_tests.rs:136:18: expected close frame, got Ping(b"")
Root Cause
The test assumes the next frame after sending malformed JSON will be a Close frame. However, the WebSocket session has a heartbeat mechanism that sends Ping frames at regular intervals. When timing aligns unfavorably, a Ping frame can arrive before the Close frame, causing the assertion to fail.
Current Code (lines 131-137)
Suggested Fix
Follow the pattern used in closes_after_timeout_without_client_messages which correctly handles intermediate Ping/Pong frames by looping until a Close frame is received:
Reproduction
The failure is timing-dependent and occurs sporadically. It was observed during CI runs for PR #277 but passes on local rerun.
Location
Labels
bug, flaky-test, backend