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>
This commit is contained in:
Copilot
2025-10-14 09:10:16 +11:00
committed by GitHub
parent a9f23018e3
commit 3eb4c7fa92

View File

@@ -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) {