From 633dbb81d151fccf1e0478be4fc086312eb4d89a Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 31 Aug 2017 15:34:55 -0700 Subject: [PATCH] fix blocking query due to ctx change --- nomad/state/state_store.go | 6 ++++-- nomad/state/state_store_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 0bef7d1aa..b1d157fff 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -122,9 +122,11 @@ RUN_QUERY: // We haven't reached the min-index yet. if minIndex > 0 && index <= minIndex { - if expired := ws.WatchCtx(ctx); !expired { - goto RUN_QUERY + if err := ws.WatchCtx(ctx); err != nil { + return nil, index, err } + + goto RUN_QUERY } return resp, index, nil diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 71f1e9003..306987367 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -51,7 +51,7 @@ func TestStateStore_Blocking_Timeout(t *testing.T) { defer cancel() _, idx, err := state.BlockingQuery(noopFn, 10, deadlineCtx) - assert.Nil(t, err) + assert.EqualError(t, err, context.DeadlineExceeded.Error()) assert.EqualValues(t, 5, idx) assert.WithinDuration(t, timeout, time.Now(), 5*time.Millisecond) }