From 0bfef847b02cb5b1f575f25127bb278f7fe08cdf Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Thu, 21 Oct 2021 10:13:09 +0200 Subject: [PATCH] discovery/consul: fix leaking goroutine from test Signed-off-by: Mateusz Gozdek --- discovery/consul/consul_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discovery/consul/consul_test.go b/discovery/consul/consul_test.go index 986c6a4d2..49b69af7d 100644 --- a/discovery/consul/consul_test.go +++ b/discovery/consul/consul_test.go @@ -307,11 +307,15 @@ func TestNoTargets(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) ch := make(chan []*targetgroup.Group) - go d.Run(ctx, ch) + go func() { + d.Run(ctx, ch) + close(ch) + }() targets := (<-ch)[0].Targets require.Equal(t, 0, len(targets)) cancel() + <-ch } // Watch only the test service.