From cfac8c47623e1928849035992ce4e1dddf01dbcb Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Mon, 8 Jul 2024 21:34:39 +0200 Subject: [PATCH] fix test timing --- relay/healthcheck/sender_test.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/relay/healthcheck/sender_test.go b/relay/healthcheck/sender_test.go index a571437ef..220bb8ac0 100644 --- a/relay/healthcheck/sender_test.go +++ b/relay/healthcheck/sender_test.go @@ -6,11 +6,14 @@ import ( "time" ) -func TestNewHealthPeriod(t *testing.T) { +func TestMain(m *testing.M) { // override the health check interval to speed up the test healthCheckInterval = 1 * time.Second healthCheckTimeout = 100 * time.Millisecond + m.Run() +} +func TestNewHealthPeriod(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() hc := NewSender(ctx) @@ -30,10 +33,6 @@ func TestNewHealthPeriod(t *testing.T) { } func TestNewHealthFailed(t *testing.T) { - // override the health check interval to speed up the test - healthCheckInterval = 1 * time.Second - healthCheckTimeout = 500 * time.Millisecond - ctx, cancel := context.WithCancel(context.Background()) defer cancel() hc := NewSender(ctx) @@ -46,18 +45,17 @@ func TestNewHealthFailed(t *testing.T) { } func TestNewHealthcheckStop(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) hc := NewSender(ctx) - time.Sleep(1 * time.Second) + time.Sleep(300 * time.Millisecond) cancel() select { case <-hc.HealthCheck: - t.Fatalf("is not closed") + t.Fatalf("health check on received") case <-hc.Timeout: - t.Fatalf("is not closed") + t.Fatalf("health check timedout") case <-ctx.Done(): // expected case <-time.After(1 * time.Second):