Skip to content

Commit

Permalink
gofail: show error messages returned by gofail HTTP endpoints
Browse files Browse the repository at this point in the history
Upon error, both PUT and DELETE will return an error message, which
would be nice for debugging if displayed.

Simplify `Enabled()` logic (linter suggestion)

Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
  • Loading branch information
henrybear327 committed Apr 25, 2024
1 parent d876d1c commit a9485dd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tests/framework/e2e/etcd_process.go
Expand Up @@ -375,7 +375,11 @@ func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload str
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("bad status code: %d", resp.StatusCode)
errMsg, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("bad status code: %d (%v)", resp.StatusCode, err)
}
return fmt.Errorf("bad status code: %d (%v)", resp.StatusCode, errMsg)
}
return nil
}
Expand Down Expand Up @@ -404,17 +408,18 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("bad status code: %d", resp.StatusCode)
errMsg, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("bad status code: %d (%v)", resp.StatusCode, err)
}
return fmt.Errorf("bad status code: %d (%v)", resp.StatusCode, errMsg)
}
return nil
}

func (f *BinaryFailpoints) Enabled() bool {
_, err := failpoints(f.member)
if err != nil {
return false
}
return true
return err == nil
}

func (f *BinaryFailpoints) Available(failpoint string) bool {
Expand Down

0 comments on commit a9485dd

Please sign in to comment.