mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
stream/match: Reduce complexity and limit locking when match occurs (#1581)
* stream match update * update tests * linter: fix * glorious: nits + handle context cancellations * glorious: whooops * Websocket: Add SendMessageReturnResponses * whooooooopsie * gk: nitssssss * Update exchanges/stream/stream_match.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/stream/stream_match_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * linter: appease the linter gods * glorious: nits * glorious: nits * Update exchanges/stream/stream_match_test.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -724,8 +725,7 @@ func TestSendMessage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSendMessageWithResponse logic test
|
||||
func TestSendMessageWithResponse(t *testing.T) {
|
||||
func TestSendMessageReturnResponse(t *testing.T) {
|
||||
t.Parallel()
|
||||
wc := &WebsocketConnection{
|
||||
Verbose: true,
|
||||
@@ -753,10 +753,20 @@ func TestSendMessageWithResponse(t *testing.T) {
|
||||
RequestID: wc.GenerateMessageID(false),
|
||||
}
|
||||
|
||||
_, err = wc.SendMessageReturnResponse(request.RequestID, request)
|
||||
_, err = wc.SendMessageReturnResponse(context.Background(), request.RequestID, request)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
cancelledCtx, fn := context.WithDeadline(context.Background(), time.Now())
|
||||
fn()
|
||||
_, err = wc.SendMessageReturnResponse(cancelledCtx, "123", request)
|
||||
assert.ErrorIs(t, err, context.DeadlineExceeded)
|
||||
|
||||
// with timeout
|
||||
wc.ResponseMaxLimit = 1
|
||||
_, err = wc.SendMessageReturnResponse(context.Background(), "123", request)
|
||||
assert.ErrorIs(t, err, ErrSignatureTimeout, "SendMessageReturnResponse should error when request ID not found")
|
||||
}
|
||||
|
||||
type reporter struct {
|
||||
@@ -1182,7 +1192,7 @@ func TestLatency(t *testing.T) {
|
||||
RequestID: wc.GenerateMessageID(false),
|
||||
}
|
||||
|
||||
_, err = wc.SendMessageReturnResponse(request.RequestID, request)
|
||||
_, err = wc.SendMessageReturnResponse(context.Background(), request.RequestID, request)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user