stream/buffer: Improve orderbook verification conditions and fix TestUpdateByIDAndAction test (#1682)

* don't need to verify if checksum available; don't retroactively verify snapshots

* glorious: nits + allow checksum/validation to be done on updateByIDAndAction

* possible slice manipulation issue fix for test

* thrasher: nit

* this should fix it now

* for subsystem usage disallow deploying a book twice

* reverts strict policy using deploy, it's used in a bunch of tests I don't want to touch just yet, left a note

* rm unused variable

* glorious: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-11-11 14:46:14 +11:00
committed by GitHub
parent a2a7fed273
commit 4de4e3dc14
4 changed files with 346 additions and 583 deletions

View File

@@ -79,8 +79,7 @@ func (s *Service) Update(b *Base) error {
return s.Mux.Publish(book, m1.ID)
}
// DeployDepth used for subsystem deployment creates a depth item in the struct
// then returns a ptr to that Depth item
// DeployDepth used for subsystem deployment creates a depth item in the struct then returns a ptr to that Depth item
func (s *Service) DeployDepth(exchange string, p currency.Pair, a asset.Item) (*Depth, error) {
if exchange == "" {
return nil, errExchangeNameUnset
@@ -112,13 +111,15 @@ func (s *Service) DeployDepth(exchange string, p currency.Pair, a asset.Item) (*
s.books[strings.ToLower(exchange)] = m1
}
book, ok := m1.m[mapKey]
if !ok {
book = NewDepth(m1.ID)
book.exchange = exchange
book.pair = p
book.asset = a
m1.m[mapKey] = book
if ok {
// Maybe in future we should return an error here and be more strict.
return book, nil
}
book = NewDepth(m1.ID)
book.exchange = exchange
book.pair = p
book.asset = a
m1.m[mapKey] = book
return book, nil
}

View File

@@ -10,6 +10,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/dispatch"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
@@ -321,28 +322,18 @@ func TestBaseGetDepth(t *testing.T) {
func TestDeployDepth(t *testing.T) {
c, err := currency.NewPairFromStrings("BTC", "USD")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
_, err = DeployDepth("", c, asset.Spot)
if !errors.Is(err, errExchangeNameUnset) {
t.Fatalf("expecting %s error but received %v", errExchangeNameUnset, err)
}
require.ErrorIs(t, err, errExchangeNameUnset)
_, err = DeployDepth("test", currency.EMPTYPAIR, asset.Spot)
if !errors.Is(err, errPairNotSet) {
t.Fatalf("expecting %s error but received %v", errPairNotSet, err)
}
require.ErrorIs(t, err, errPairNotSet)
_, err = DeployDepth("test", c, asset.Empty)
if !errors.Is(err, errAssetTypeNotSet) {
t.Fatalf("expecting %s error but received %v", errAssetTypeNotSet, err)
}
require.ErrorIs(t, err, errAssetTypeNotSet)
d, err := DeployDepth("test", c, asset.Spot)
if err != nil {
t.Fatal(err)
}
if d == nil {
t.Fatal("depth ptr shall not be nill")
}
require.NoError(t, err)
require.NotNil(t, d)
_, err = DeployDepth("test", c, asset.Spot)
require.NoError(t, err)
}
func TestCreateNewOrderbook(t *testing.T) {