Skip to content

Commit 2bec17c

Browse files
committed
Fix flaky hoverctl functional test
1 parent c8cfce6 commit 2bec17c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

functional-tests/functional_tests.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,21 @@ func (this Hoverfly) Stop() {
9595
}
9696

9797
func (this Hoverfly) StopAPIAuthenticated(username, password string) {
98-
token, err := this.getAPIToken(username, password)
99-
if err != nil {
100-
return
101-
}
102-
_, err = doRequest(sling.New().Delete(this.adminUrl+"/api/v2/shutdown").Add("Authorization", "Bearer "+token))
103-
if err != nil {
104-
panic(err)
105-
}
98+
// In teardown, we should be tolerant to failures when shutting down.
99+
// If Hoverfly is already stopped or the connection closes early (EOF), just return.
100+
token, err := this.getAPIToken(username, password)
101+
if err != nil {
102+
return
103+
}
104+
resp, err := doRequest(sling.New().Delete(this.adminUrl+"/api/v2/shutdown").Add("Authorization", "Bearer "+token))
105+
if resp != nil && resp.Body != nil {
106+
io.Copy(io.Discard, resp.Body)
107+
resp.Body.Close()
108+
}
109+
if err != nil {
110+
// swallow error to avoid panicking AfterEach
111+
return
112+
}
106113
}
107114

108115
func (this Hoverfly) DeleteBoltDb() {

0 commit comments

Comments
 (0)