mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Tests: Abstract UpdatePairsOnce (#1503)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -141,7 +142,7 @@ func SetupWs(tb testing.TB, e exchange.IBotExchange) {
|
||||
setupWsMutex.Lock()
|
||||
defer setupWsMutex.Unlock()
|
||||
|
||||
if _, ok := setupWsOnce[e]; ok {
|
||||
if setupWsOnce[e] {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -157,3 +158,23 @@ func SetupWs(tb testing.TB, e exchange.IBotExchange) {
|
||||
|
||||
setupWsOnce[e] = true
|
||||
}
|
||||
|
||||
var updatePairsMutex sync.Mutex
|
||||
var updatePairsOnce = make(map[exchange.IBotExchange]bool)
|
||||
|
||||
// UpdatePairsOnce ensures pairs are only updated once in parallel tests
|
||||
func UpdatePairsOnce(tb testing.TB, e exchange.IBotExchange) {
|
||||
tb.Helper()
|
||||
|
||||
updatePairsMutex.Lock()
|
||||
defer updatePairsMutex.Unlock()
|
||||
|
||||
if updatePairsOnce[e] {
|
||||
return
|
||||
}
|
||||
|
||||
err := e.UpdateTradablePairs(context.Background(), true)
|
||||
require.NoError(tb, err, "UpdateTradablePairs must not error")
|
||||
|
||||
updatePairsOnce[e] = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user