Merge pull request #11235 from hashicorp/test-evalbroker

test: fix fake by increasing time window
This commit is contained in:
Michael Schurter 2021-10-04 11:16:41 -07:00 committed by GitHub
commit 20cf993b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -325,7 +325,11 @@ func (b *EvalBroker) enqueueLocked(eval *structs.Evaluation, queue string) {
}
}
// Dequeue is used to perform a blocking dequeue
// Dequeue is used to perform a blocking dequeue. The next available evalution
// is returned as well as a unique token identifier for this dequeue. The token
// changes on leadership election to ensure a Dequeue prior to a leadership
// election cannot conflict with a Dequeue of the same evaluation after a
// leadership election.
func (b *EvalBroker) Dequeue(schedulers []string, timeout time.Duration) (*structs.Evaluation, string, error) {
var timeoutTimer *time.Timer
var timeoutCh <-chan time.Time

View File

@ -1196,7 +1196,8 @@ func TestEvalBroker_AckAtDeliveryLimit(t *testing.T) {
}
}
// Ensure fairness between schedulers
// TestEvalBroker_Wait asserts delayed evaluations cannot be dequeued until
// their wait duration has elapsed.
func TestEvalBroker_Wait(t *testing.T) {
t.Parallel()
b := testBroker(t, 0)
@ -1204,7 +1205,7 @@ func TestEvalBroker_Wait(t *testing.T) {
// Create an eval that should wait
eval := mock.Eval()
eval.Wait = 10 * time.Millisecond
eval.Wait = 100 * time.Millisecond
b.Enqueue(eval)
// Verify waiting
@ -1216,8 +1217,14 @@ func TestEvalBroker_Wait(t *testing.T) {
t.Fatalf("bad: %#v", stats)
}
// Dequeue should not return the eval until wait has elapsed
out, token, err := b.Dequeue(defaultSched, 1)
require.Nil(t, out)
require.Empty(t, token)
require.NoError(t, err)
// Let the wait elapse
time.Sleep(20 * time.Millisecond)
time.Sleep(200 * time.Millisecond)
// Verify ready
stats = b.Stats()
@ -1229,7 +1236,7 @@ func TestEvalBroker_Wait(t *testing.T) {
}
// Dequeue should work
out, _, err := b.Dequeue(defaultSched, time.Second)
out, _, err = b.Dequeue(defaultSched, time.Second)
if err != nil {
t.Fatalf("err: %v", err)
}