From 7c6d5ff2e867a40aa927abff826886154234c5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Mon, 11 Nov 2024 10:42:29 +0100 Subject: [PATCH] multicast/discovery: Avoid leaking the context in tests (govet) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- multicast/discovery_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/multicast/discovery_test.go b/multicast/discovery_test.go index 30e2830b1..25f539a0b 100644 --- a/multicast/discovery_test.go +++ b/multicast/discovery_test.go @@ -103,8 +103,9 @@ func (m *multicastSuite) Test_Lookup() { testDiscovery := NewDiscovery(c.lookupIface, c.lookupPort) ctx := context.Background() + var cancel context.CancelFunc if c.lookupTimeout > 0 { - ctx, _ = context.WithTimeoutCause(ctx, c.lookupTimeout, fmt.Errorf("Timeout exceeded")) + ctx, cancel = context.WithTimeoutCause(ctx, c.lookupTimeout, fmt.Errorf("Timeout exceeded")) } receivedInfo, err := testDiscovery.Lookup(ctx, c.lookupVersion) @@ -116,6 +117,11 @@ func (m *multicastSuite) Test_Lookup() { m.Require().Equal(c.lookupErr.Error(), err.Error()) } + // Cancel the timeout to avoid leaking the context. + if cancel != nil { + cancel() + } + // Stop the responder. err = discovery.StopResponder() m.Require().NoError(err)