mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
exchanges/GateIO, OKX: Fix and optimise websocket request ID message generation (#2103)
* gatio: fix MessageID regression (cherry-pick me) * Update exchanges/gateio/gateio_wrapper_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * glorious: AI * Update exchanges/gateio/gateio_wrapper.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * thrasher: use optimisation in okx as well * okx: Add length check in tests for string -> uuid conversion * thrasher: nits --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package gateio
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
@@ -71,3 +72,20 @@ func TestCancelAllOrders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageID(t *testing.T) {
|
||||
t.Parallel()
|
||||
id := e.MessageID()
|
||||
require.Len(t, id, 32, "message ID must be 32 characters long for usage as a request ID")
|
||||
got, err := uuid.FromString(id)
|
||||
require.NoError(t, err, "ID string must convert back to a UUID")
|
||||
require.Equal(t, uuid.V7, got.Version(), "message ID must be a UUID v7")
|
||||
require.Len(t, got.String(), 36, "UUID v7 string representation must be 36 characters long")
|
||||
}
|
||||
|
||||
// 7610378 143.3 ns/op 48 B/op 2 allocs/op
|
||||
func BenchmarkMessageID(b *testing.B) {
|
||||
for b.Loop() {
|
||||
_ = e.MessageID()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user