Skip to content

Commit

Permalink
Merge pull request #4105 from hashicorp/b-flaky-deadline-tests
Browse files Browse the repository at this point in the history
Fix flaky deadline tests
  • Loading branch information
dadgar committed Apr 4, 2018
2 parents 85c41a6 + 4cfe3a5 commit 69bb648
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 9 additions & 8 deletions nomad/drainer/drain_heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,7 +30,7 @@ func TestDeadlineHeap_WatchAndGet(t *testing.T) {
var batch []string
select {
case batch = <-h.NextBatch():
case <-time.After(2 * wait):
case <-time.After(testutil.Timeout(2 * wait)):
t.Fatal("timeout")
}

Expand All @@ -56,7 +57,7 @@ func TestDeadlineHeap_WatchThenUpdateAndGet(t *testing.T) {
var batch []string
select {
case batch = <-h.NextBatch():
case <-time.After(2 * wait):
case <-time.After(testutil.Timeout(2 * wait)):
t.Fatal("timeout")
}

Expand Down Expand Up @@ -84,7 +85,7 @@ func TestDeadlineHeap_MultiwatchAndDelete(t *testing.T) {
var batch []string
select {
case batch = <-h.NextBatch():
case <-time.After(2 * wait):
case <-time.After(testutil.Timeout(2 * wait)):
t.Fatal("timeout")
}

Expand Down Expand Up @@ -120,7 +121,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {
var batch []string
select {
case batch = <-h.NextBatch():
case <-time.After(1 * time.Second):
case <-time.After(testutil.Timeout(time.Second)):
t.Fatal("timeout")
}

Expand All @@ -132,7 +133,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {

select {
case batch = <-h.NextBatch():
case <-time.After(2 * time.Second):
case <-time.After(testutil.Timeout(2 * time.Second)):
t.Fatal("timeout")
}

Expand All @@ -144,7 +145,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {
select {
case <-h.NextBatch():
t.Fatal("unexpected batch")
case <-time.After(100 * time.Millisecond):
case <-time.After(testutil.Timeout(100 * time.Millisecond)):
}
}

Expand All @@ -160,7 +161,7 @@ func TestDeadlineHeap_MultipleForce(t *testing.T) {
var batch []string
select {
case batch = <-h.NextBatch():
case <-time.After(10 * time.Millisecond):
case <-time.After(testutil.Timeout(10 * time.Millisecond)):
t.Fatal("timeout")
}

Expand All @@ -171,7 +172,7 @@ func TestDeadlineHeap_MultipleForce(t *testing.T) {
h.Watch(nodeID, deadline)
select {
case batch = <-h.NextBatch():
case <-time.After(10 * time.Millisecond):
case <-time.After(testutil.Timeout(10 * time.Millisecond)):
t.Fatal("timeout")
}

Expand Down
5 changes: 5 additions & 0 deletions testutil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func TestMultiplier() int64 {
return 1
}

// Timeout takes the desired timeout and increases it if running in Travis
func Timeout(original time.Duration) time.Duration {
return original * time.Duration(TestMultiplier())
}

func IsTravis() bool {
_, ok := os.LookupEnv(TravisRunEnv)
return ok
Expand Down

0 comments on commit 69bb648

Please sign in to comment.