mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Huobi: Fix TestPairFromContractExpiryCode intermittent failure (#2052)
Huobi decided to not even return CW at all in [this test](https://github.com/thrasher-corp/gocryptotrader/actions/runs/17637897980/job/50117883059?pr=1990#step:11:1280) Reverse the test expectation. Just get *something* back in contract codes. We have to accept that runtime won't work sometimes when we want to convert codes that they haven't told us about... and that's the way it is.
This commit is contained in:
@@ -1810,6 +1810,8 @@ var expiryWindows = map[string]uint{
|
||||
"NQ": 282,
|
||||
}
|
||||
|
||||
// TestPairFromContractExpiryCode ensures at least some contract codes are available and loaded with sane dates
|
||||
// Expectations are relaxed because dates are unpredictable and codes disappear intermittently
|
||||
func TestPairFromContractExpiryCode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -1825,30 +1827,27 @@ func TestPairFromContractExpiryCode(t *testing.T) {
|
||||
today := time.Now()
|
||||
today = time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, tz) // Do not use Truncate; https://github.com/golang/go/issues/55921
|
||||
|
||||
for _, cType := range contractExpiryNames {
|
||||
p, err := e.pairFromContractExpiryCode(currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.NewCode(cType),
|
||||
require.NotEmpty(t, e.futureContractCodes, "At least one contract code must be loaded")
|
||||
|
||||
for cType, cachedContract := range e.futureContractCodes {
|
||||
t.Run(cType, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
p, err := e.pairFromContractExpiryCode(currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.NewCode(cType),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, currency.BTC, p.Base, "pair Base should be BTC")
|
||||
assert.Equal(t, cachedContract, p.Quote, "pair Quote should match futureContractCodes value")
|
||||
exp, err := time.ParseInLocation("060102", p.Quote.String(), tz)
|
||||
require.NoError(t, err, "currency code must be a parsable date")
|
||||
require.Falsef(t, exp.Before(today), "expiry must be today or after; Got: %q", exp)
|
||||
diff := uint(exp.Sub(today).Hours() / 24)
|
||||
require.LessOrEqualf(t, diff, expiryWindows[cType], "expiry must be within expected update window; Today: %q, Expiry: %q",
|
||||
today.Format(time.DateOnly),
|
||||
exp.Format(time.DateOnly),
|
||||
)
|
||||
})
|
||||
if cType == "NQ" && err != nil {
|
||||
continue // Next Quarter is intermittently present
|
||||
}
|
||||
require.NoErrorf(t, err, "pairFromContractExpiryCode must not error for %s code", cType)
|
||||
assert.Equal(t, currency.BTC, p.Base, "pair Base should be BTC")
|
||||
e.futureContractCodesMutex.RLock()
|
||||
cachedContract, ok := e.futureContractCodes[cType]
|
||||
e.futureContractCodesMutex.RUnlock()
|
||||
require.Truef(t, ok, "%s type must be in futureContractCodes", cType)
|
||||
assert.Equal(t, cachedContract, p.Quote, "pair Quote should match contractExpiryNames")
|
||||
exp, err := time.ParseInLocation("060102", p.Quote.String(), tz)
|
||||
require.NoError(t, err, "currency code must be a parsable date")
|
||||
require.Falsef(t, exp.Before(today), "%s expiry must be today or after; Got: %q", cType, exp)
|
||||
diff := uint(exp.Sub(today).Hours() / 24)
|
||||
require.LessOrEqualf(t, diff, expiryWindows[cType], "%s expiry must be within expected update window; Today: %q, Expiry: %q",
|
||||
cType,
|
||||
today.Format(time.DateOnly),
|
||||
exp.Format(time.DateOnly),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user