From 0d71c615cd13feeaba371c8a4f54e8a6c9236672 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Sat, 17 Feb 2024 09:05:59 +0700 Subject: [PATCH] fixup! Websocket: Fix and simplify traffic monitor Fix race on changing trafficCheckInterval --- exchanges/stream/websocket_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/exchanges/stream/websocket_test.go b/exchanges/stream/websocket_test.go index 692d84bed4a..ce2949d6dc7 100644 --- a/exchanges/stream/websocket_test.go +++ b/exchanges/stream/websocket_test.go @@ -105,6 +105,11 @@ func (d *dodgyConnection) Connect() error { return fmt.Errorf("cannot connect: %w", errDastardlyReason) } +func TestMain(m *testing.M) { + // Change trafficCheckInterval for TestTrafficMonitorTimeout before parallel tests to avoid racing + trafficCheckInterval = 50 * time.Millisecond +} + func TestSetup(t *testing.T) { t.Parallel() var w *Websocket @@ -183,7 +188,7 @@ func TestTrafficMonitorTimeout(t *testing.T) { signal := struct{}{} patience := 10 * time.Millisecond - trafficCheckInterval = 50 * time.Millisecond + // trafficCheckInterval is changed in TestMain to avoid racing ws.trafficTimeout = 200 * time.Millisecond ws.ShutdownC = make(chan struct{})