Skip to content

Commit

Permalink
Huobi: Fix test failures on futureContracts
Browse files Browse the repository at this point in the history
Per-instance future codes not getting cached causin occassional fails
  • Loading branch information
gbjk committed Dec 18, 2024
1 parent c942589 commit 52dfbfd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exchanges/huobi/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ func TestBootstrap(t *testing.T) {
}

var updatePairsMutex sync.Mutex
var futureContractCodesCache map[string]currency.Code

// updatePairsOnce updates the pairs once, and ensures a future dated contract is enabled
func updatePairsOnce(tb testing.TB, h *HUOBI) {
Expand All @@ -2038,6 +2039,16 @@ func updatePairsOnce(tb testing.TB, h *HUOBI) {

testexch.UpdatePairsOnce(tb, h)

h.futureContractCodesMutex.Lock()
if len(h.futureContractCodes) == 0 {
// Restored pairs from cache, so haven't populated futureContract Codes
require.NotEmpty(tb, futureContractCodesCache, "futureContractCodesCache must not be empty")
h.futureContractCodes = futureContractCodesCache
} else {
futureContractCodesCache = h.futureContractCodes
}
h.futureContractCodesMutex.Unlock()

if btcFutureDatedPair.Equal(currency.EMPTYPAIR) {
p, err := h.pairFromContractExpiryCode(btccwPair)
require.NoError(tb, err, "pairFromContractCode must not error")
Expand Down

0 comments on commit 52dfbfd

Please sign in to comment.