Skip to content

Commit

Permalink
Ensure that httptest.Server is always closed.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Dec 5, 2023
1 parent 49b30c4 commit be8ba87
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/agent/agent_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ func TestWatchErrorSendingSnapshot(t *testing.T) {
_, err = w.Write(enSnapshot)
assert.NoError(t, err)
}))
tsClosed := false
defer func() {
// If we missed closing the server due to a fatal error
if !tsClosed {
ts.Close()
}
}()
a.AESSnapshotURL = parseURL(t, ts.URL)
mockError := errors.New("MockClient: Error sending report")

Expand Down Expand Up @@ -609,6 +616,7 @@ func TestWatchErrorSendingSnapshot(t *testing.T) {
t.Fatal("Timed out waiting for report to complete.")
}
ts.Close()
tsClosed = true

select {
case err := <-watchDone:
Expand Down

0 comments on commit be8ba87

Please sign in to comment.