Skip to content

Commit

Permalink
Make TestHealthCheckHandlerContext_ServeHTTP more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
vasayxtx committed Aug 26, 2024
1 parent a928702 commit bb8e330
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion httpserver/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func NewHealthCheckHandlerContext(fn HealthCheckContext) *HealthCheckHandler {
func (h *HealthCheckHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
hcResult, err := h.healthCheckFn(r.Context())
if err != nil {
middleware.GetLoggerFromContext(r.Context()).Error("error while checking health", log.Error(err))
if logger := middleware.GetLoggerFromContext(r.Context()); logger != nil {
logger.Error("error while checking health", log.Error(err))
}
if errors.Is(err, context.Canceled) {
rw.WriteHeader(StatusClientClosedRequest)
return
Expand Down
2 changes: 1 addition & 1 deletion httpserver/health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestHealthCheckHandlerContext_ServeHTTP(t *testing.T) {
})

t.Run("health-check responds error on client timeout", func(t *testing.T) {
const requestTimeout = 10 * time.Millisecond
const requestTimeout = 100 * time.Millisecond

h := NewHealthCheckHandlerContext(func(ctx context.Context) (HealthCheckResult, error) {
select {
Expand Down

0 comments on commit bb8e330

Please sign in to comment.