From ff2d929e2bf56e9520725b4c32aaf23b5e099dfe Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 7 Feb 2017 11:35:38 -0800 Subject: [PATCH] Fix test --- nomad/state/state_store_test.go | 67 +++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index a155f9031..5ad3b89b1 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -2098,32 +2098,7 @@ func TestStateStore_UpdateAllocsFromClient(t *testing.T) { t.Fatalf("err: %v", err) } - // Create watchsets so we can test that update fires the watch ws := memdb.NewWatchSet() - if _, err := state.JobSummaryByID(ws, parent.ID); err != nil { - t.Fatalf("bad: %v", err) - } - - // Create the delta updates - ts := map[string]*structs.TaskState{"web": &structs.TaskState{State: structs.TaskStateRunning}} - update := &structs.Allocation{ - ID: alloc.ID, - ClientStatus: structs.AllocClientStatusRunning, - TaskStates: ts, - JobID: alloc.JobID, - TaskGroup: alloc.TaskGroup, - } - err = state.UpdateAllocsFromClient(1001, []*structs.Allocation{update}) - if err != nil { - t.Fatalf("err: %v", err) - } - - // XXX why is this failing - //if !watchFired(ws) { - //t.Fatalf("bad") - //} - - ws = memdb.NewWatchSet() summary, err := state.JobSummaryByID(ws, parent.ID) if err != nil { t.Fatalf("err: %v", err) @@ -2141,6 +2116,48 @@ func TestStateStore_UpdateAllocsFromClient(t *testing.T) { t.Fatalf("bad children summary: %v", summary.Children) } + // Create watchsets so we can test that update fires the watch + ws = memdb.NewWatchSet() + if _, err := state.JobSummaryByID(ws, parent.ID); err != nil { + t.Fatalf("bad: %v", err) + } + + // Create the delta updates + ts := map[string]*structs.TaskState{"web": &structs.TaskState{State: structs.TaskStateRunning}} + update := &structs.Allocation{ + ID: alloc.ID, + ClientStatus: structs.AllocClientStatusComplete, + TaskStates: ts, + JobID: alloc.JobID, + TaskGroup: alloc.TaskGroup, + } + err = state.UpdateAllocsFromClient(1001, []*structs.Allocation{update}) + if err != nil { + t.Fatalf("err: %v", err) + } + + if !watchFired(ws) { + t.Fatalf("bad") + } + + ws = memdb.NewWatchSet() + summary, err = state.JobSummaryByID(ws, parent.ID) + if err != nil { + t.Fatalf("err: %v", err) + } + if summary == nil { + t.Fatalf("nil summary") + } + if summary.JobID != parent.ID { + t.Fatalf("bad summary id: %v", parent.ID) + } + if summary.Children == nil { + t.Fatalf("nil children summary") + } + if summary.Children.Pending != 0 || summary.Children.Running != 0 || summary.Children.Dead != 1 { + t.Fatalf("bad children summary: %v", summary.Children) + } + if watchFired(ws) { t.Fatalf("bad") }