From 3eb4c7fa921d373f5a1585795430effb39b601a2 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 09:10:16 +1100 Subject: [PATCH] exchange/websocket: Fix TestMatchReturnResponses race condition causing index out of range panic (#2079) * Initial plan * Fix TestMatchReturnResponses race condition panic Co-authored-by: thrasher- <4685270+thrasher-@users.noreply.github.com> * Add require.NotEmpty check on resp.Responses to prevent panic Co-authored-by: shazbert <9391715+shazbert@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thrasher- <4685270+thrasher-@users.noreply.github.com> Co-authored-by: shazbert <9391715+shazbert@users.noreply.github.com> --- exchange/websocket/connection_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exchange/websocket/connection_test.go b/exchange/websocket/connection_test.go index 003c2a72..38df6ef8 100644 --- a/exchange/websocket/connection_test.go +++ b/exchange/websocket/connection_test.go @@ -19,14 +19,17 @@ func TestMatchReturnResponses(t *testing.T) { require.NoError(t, err) require.ErrorIs(t, (<-ch).Err, ErrSignatureTimeout) - conn.ResponseMaxLimit = time.Millisecond + conn.ResponseMaxLimit = time.Second ch, err = conn.MatchReturnResponses(t.Context(), nil, 1) require.NoError(t, err) exp := []byte("test") require.True(t, conn.Match.IncomingWithData(nil, exp)) - assert.Equal(t, exp, (<-ch).Responses[0]) + resp := <-ch + require.NoError(t, resp.Err) + require.NotEmpty(t, resp.Responses, "must have response data") + assert.Equal(t, exp, resp.Responses[0]) } func TestWebsocketConnectionRequireMatchWithData(t *testing.T) {