Skip to content

Commit

Permalink
multicast/discovery: Avoid leaking the context in tests (govet)
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Nov 11, 2024
1 parent eaca1e1 commit 7c6d5ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion multicast/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7c6d5ff

Please sign in to comment.