Skip to content

Commit

Permalink
lib: always show timeout duration in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
cuonglm committed Sep 24, 2019
1 parent 015b5b6 commit 4526005
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/timeout_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ func NewTimeoutError(place string, d time.Duration) TimeoutError {

// String returns timeout error in human readable format.
func (t TimeoutError) String() string {
s := t.place + " execution timed out"
if t.d.Seconds() > 0 {
s += fmt.Sprintf(" after %.f seconds", t.d.Seconds())
}
return s
return fmt.Sprintf("%s execution timed out after %.f seconds", t.place, t.d.Seconds())
}

// Error implements error interface.
Expand Down
19 changes: 19 additions & 0 deletions lib/timeout_error_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
package lib

import (
"strings"
"testing"
"time"
)

func TestTimeoutError(t *testing.T) {
tests := []struct {
stage, expectedStrContain string
d time.Duration
}{
{"setup", "1 seconds", time.Second},
{"teardown", "2 seconds", time.Second * 2},
{"", "0 seconds", time.Duration(0)},
}

for _, tc := range tests {
te := NewTimeoutError(tc.stage, tc.d)
if !strings.Contains(te.String(), tc.expectedStrContain) {
t.Errorf("Expected error contains %s, but got: %s", tc.expectedStrContain, te.String())
}
}
}

func TestTimeoutErrorHint(t *testing.T) {
tests := []struct {
stage string
Expand Down

0 comments on commit 4526005

Please sign in to comment.