Merge pull request #4105 from hashicorp/b-flaky-deadline-tests
Fix flaky deadline tests
This commit is contained in:
commit
345169a3cc
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/nomad/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ func TestDeadlineHeap_WatchAndGet(t *testing.T) {
|
||||||
var batch []string
|
var batch []string
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(2 * wait):
|
case <-time.After(testutil.Timeout(2 * wait)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ func TestDeadlineHeap_WatchThenUpdateAndGet(t *testing.T) {
|
||||||
var batch []string
|
var batch []string
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(2 * wait):
|
case <-time.After(testutil.Timeout(2 * wait)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ func TestDeadlineHeap_MultiwatchAndDelete(t *testing.T) {
|
||||||
var batch []string
|
var batch []string
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(2 * wait):
|
case <-time.After(testutil.Timeout(2 * wait)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +121,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {
|
||||||
var batch []string
|
var batch []string
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(1 * time.Second):
|
case <-time.After(testutil.Timeout(time.Second)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(2 * time.Second):
|
case <-time.After(testutil.Timeout(2 * time.Second)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ func TestDeadlineHeap_WatchCoalesce(t *testing.T) {
|
||||||
select {
|
select {
|
||||||
case <-h.NextBatch():
|
case <-h.NextBatch():
|
||||||
t.Fatal("unexpected batch")
|
t.Fatal("unexpected batch")
|
||||||
case <-time.After(100 * time.Millisecond):
|
case <-time.After(testutil.Timeout(100 * time.Millisecond)):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ func TestDeadlineHeap_MultipleForce(t *testing.T) {
|
||||||
var batch []string
|
var batch []string
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(10 * time.Millisecond):
|
case <-time.After(testutil.Timeout(10 * time.Millisecond)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +172,7 @@ func TestDeadlineHeap_MultipleForce(t *testing.T) {
|
||||||
h.Watch(nodeID, deadline)
|
h.Watch(nodeID, deadline)
|
||||||
select {
|
select {
|
||||||
case batch = <-h.NextBatch():
|
case batch = <-h.NextBatch():
|
||||||
case <-time.After(10 * time.Millisecond):
|
case <-time.After(testutil.Timeout(10 * time.Millisecond)):
|
||||||
t.Fatal("timeout")
|
t.Fatal("timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,11 @@ func TestMultiplier() int64 {
|
||||||
return 1
|
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 {
|
func IsTravis() bool {
|
||||||
_, ok := os.LookupEnv(TravisRunEnv)
|
_, ok := os.LookupEnv(TravisRunEnv)
|
||||||
return ok
|
return ok
|
||||||
|
|
Loading…
Reference in a new issue