mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Tests: Various race fixes and move TestFixtureToDataHandler (#1534)
* Tests: Move and simplify TestFixtureToDataHandler * Currency: Fix PairsManager.Load breaking matcher * Tests: Add multi-instance cache to UpdatePairsOnce * Kraken: Fix TestUpdateTickers race error Calling StorePairs on global instance can lead to race * Bitfinex: Fix TestUpdateTickers racing intermittently * Currency: Fix concurrent access to PM formats * Currency: Fix SupportsAsset implementation This should delegate entirely to PairManager's IsAssetSupported * Okx: Fix PM intrusion, rm GetPairFromInstrumentID * Exchange: Fix SetGlobalPairsManager to set asset enabled * Bitflyer: Fix race on set TestGetCurrURL TestGetCurrencyTradeURL would fail sometimes due to sequencing of enabling futures but not having pairs for it. * Tests: Simplify usage pattern for FixtureToDH
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package sharedtestvalues
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -9,15 +8,14 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stream/buffer"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/subscription"
|
||||
)
|
||||
|
||||
@@ -64,6 +62,7 @@ func NewTestWebsocket() *stream.Websocket {
|
||||
Subscribe: make(chan []subscription.Subscription, 10),
|
||||
Unsubscribe: make(chan []subscription.Subscription, 10),
|
||||
Match: stream.NewMatch(),
|
||||
Orderbook: buffer.Orderbook{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,38 +153,6 @@ func ForceFileStandard(t *testing.T, pattern string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestFixtureToDataHandler takes a new empty exchange and configures a new websocket handler for it, and squirts the json path contents to it
|
||||
// It accepts a reader function, which is probably e.wsHandleData but could be anything
|
||||
func TestFixtureToDataHandler(t *testing.T, seed, e exchange.IBotExchange, fixturePath string, reader func([]byte) error) {
|
||||
t.Helper()
|
||||
b := e.GetBase()
|
||||
seedBase := seed.GetBase()
|
||||
|
||||
err := b.CurrencyPairs.Load(&seedBase.CurrencyPairs)
|
||||
assert.NoError(t, err, "Loading currency pairs should not error")
|
||||
|
||||
b.Name = "fixture"
|
||||
b.Websocket = &stream.Websocket{
|
||||
Wg: new(sync.WaitGroup),
|
||||
DataHandler: make(chan interface{}, 128),
|
||||
}
|
||||
b.API.Endpoints = b.NewEndpoints()
|
||||
|
||||
fixture, err := os.Open(fixturePath)
|
||||
assert.NoError(t, err, "Opening fixture '%s' should not error", fixturePath)
|
||||
defer func() {
|
||||
assert.NoError(t, fixture.Close(), "Closing the fixture file should not error")
|
||||
}()
|
||||
|
||||
s := bufio.NewScanner(fixture)
|
||||
for s.Scan() {
|
||||
msg := s.Bytes()
|
||||
err := reader(msg)
|
||||
assert.NoErrorf(t, err, "Fixture message should not error:\n%s", msg)
|
||||
}
|
||||
assert.NoError(t, s.Err(), "Fixture Scanner should not error")
|
||||
}
|
||||
|
||||
// SetupCurrencyPairsForExchangeAsset enables an asset for an exchange
|
||||
// and adds the currency pair(s) to the available and enabled list of existing pairs
|
||||
// if it is already enabled or part of the pairs, no error is raised
|
||||
|
||||
Reference in New Issue
Block a user