Huobi: Relax TestPairFromContractExpiryCode expiry date tests (#1903)

We saw another false negative failure on huobi NW testing [here](https://github.com/thrasher-corp/gocryptotrader/actions/runs/14926487990/job/41932452598?pr=1901#step:11:731)

On Friday 2025-05-09 the end date for the next week moved to 2025-05-25.

This fix relaxes our tests, and handles the predictable failure on Next Quarter in the same manner as Next Week.
For the quarterly tests, we add another 7 days.

Hopefully this will be the end of this recurring test failure.
This commit is contained in:
Gareth Kirwan
2025-05-20 10:48:00 +02:00
committed by GitHub
parent b18cc1cdde
commit 8c678063b5

View File

@@ -1815,6 +1815,13 @@ func TestUpdateTickers(t *testing.T) {
}
}
var expiryWindows = map[string]uint{
"CW": 14,
"NW": 21,
"CQ": 190,
"NQ": 282,
}
func TestPairFromContractExpiryCode(t *testing.T) {
t.Parallel()
@@ -1827,8 +1834,8 @@ func TestPairFromContractExpiryCode(t *testing.T) {
tz, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective
require.NoError(t, err, "LoadLocation must not error")
n := time.Now()
n = time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, tz) // Do not use Truncate; https://github.com/golang/go/issues/55921
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 := h.pairFromContractExpiryCode(currency.Pair{
@@ -1839,22 +1846,21 @@ func TestPairFromContractExpiryCode(t *testing.T) {
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 the same")
assert.Equal(t, currency.BTC, p.Base, "pair Base should be BTC")
h.futureContractCodesMutex.RLock()
exp, ok := h.futureContractCodes[cType]
cachedContract, ok := h.futureContractCodes[cType]
h.futureContractCodesMutex.RUnlock()
require.True(t, ok, "%s type must be in contractExpiryNames", cType)
assert.Equal(t, currency.BTC, p.Base, "pair Base should be the same")
assert.Equal(t, exp, p.Quote, "pair Quote should be the same")
d, err := time.ParseInLocation("060102", p.Quote.String(), tz)
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, d.Before(n), "%s expiry must be today or after", cType)
switch cType {
case "CW", "NW":
require.Truef(t, d.Before(n.AddDate(0, 0, 14)), "%s expiry must be within 14 days; Got: `%s`", cType, d)
case "CQ", "NQ":
require.Truef(t, d.Before(n.AddDate(0, 6, 0)), "%s expiry must be within 6 months; Got: `%s`", cType, d)
}
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),
)
}
}