| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package deps | 5 package deps |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 "github.com/luci/gae/service/datastore" | 11 "github.com/luci/gae/service/datastore" |
| 12 "github.com/luci/luci-go/appengine/cmd/dm/model" | 12 "github.com/luci/luci-go/appengine/cmd/dm/model" |
| 13 "github.com/luci/luci-go/appengine/tumble" | |
| 14 "github.com/luci/luci-go/common/api/dm/service/v1" | 13 "github.com/luci/luci-go/common/api/dm/service/v1" |
| 15 . "github.com/luci/luci-go/common/testing/assertions" | 14 . "github.com/luci/luci-go/common/testing/assertions" |
| 16 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
| 17 ) | 16 ) |
| 18 | 17 |
| 19 func TestAddDeps(t *testing.T) { | 18 func TestAddDeps(t *testing.T) { |
| 20 t.Parallel() | 19 t.Parallel() |
| 21 | 20 |
| 22 Convey("EnsureGraphData (Adding deps)", t, func() { | 21 Convey("EnsureGraphData (Adding deps)", t, func() { |
| 23 » » ttest := &tumble.Testing{} | 22 » » _, c, _, s := testSetup() |
| 24 » » c := ttest.Context() | |
| 25 ds := datastore.Get(c) | 23 ds := datastore.Get(c) |
| 26 s := newDecoratedDeps() | |
| 27 zt := time.Time{} | 24 zt := time.Time{} |
| 28 | 25 |
| 29 a := &model.Attempt{ID: *dm.NewAttemptID("quest", 1)} | 26 a := &model.Attempt{ID: *dm.NewAttemptID("quest", 1)} |
| 30 a.CurExecution = 1 | 27 a.CurExecution = 1 |
| 31 a.State = dm.Attempt_EXECUTING | 28 a.State = dm.Attempt_EXECUTING |
| 32 ak := ds.KeyForObj(a) | 29 ak := ds.KeyForObj(a) |
| 33 | 30 |
| 34 e := &model.Execution{ | 31 e := &model.Execution{ |
| 35 ID: 1, Attempt: ak, Token: []byte("key"), | 32 ID: 1, Attempt: ak, Token: []byte("key"), |
| 36 State: dm.Execution_RUNNING} | 33 State: dm.Execution_RUNNING} |
| 37 | 34 |
| 38 toQuestDesc := &dm.Quest_Desc{ | 35 toQuestDesc := &dm.Quest_Desc{ |
| 39 » » » DistributorConfigName: "foof", | 36 » » » DistributorConfigName: "fakeDistributor", |
| 40 JsonPayload: `{"data":"yes"}`, | 37 JsonPayload: `{"data":"yes"}`, |
| 41 } | 38 } |
| 42 » » toQuest, err := model.NewQuest(c, toQuestDesc) | 39 » » So(toQuestDesc.Normalize(), ShouldBeNil) |
| 43 » » So(err, ShouldBeNil) | 40 » » toQuest := model.NewQuest(c, toQuestDesc) |
| 44 to := &model.Attempt{ID: *dm.NewAttemptID(toQuest.ID, 1)} | 41 to := &model.Attempt{ID: *dm.NewAttemptID(toQuest.ID, 1)} |
| 45 fwd := &model.FwdDep{Depender: ak, Dependee: to.ID} | 42 fwd := &model.FwdDep{Depender: ak, Dependee: to.ID} |
| 46 | 43 |
| 47 req := &dm.EnsureGraphDataReq{ | 44 req := &dm.EnsureGraphDataReq{ |
| 48 ForExecution: &dm.Execution_Auth{ | 45 ForExecution: &dm.Execution_Auth{ |
| 49 Id: dm.NewExecutionID(a.ID.Quest, a.ID.Id, 1)
, | 46 Id: dm.NewExecutionID(a.ID.Quest, a.ID.Id, 1)
, |
| 50 Token: []byte("key"), | 47 Token: []byte("key"), |
| 51 }, | 48 }, |
| 52 Attempts: dm.NewAttemptList(map[string][]uint32{ | 49 Attempts: dm.NewAttemptList(map[string][]uint32{ |
| 53 to.ID.Quest: {to.ID.Id}, | 50 to.ID.Quest: {to.ID.Id}, |
| 54 }), | 51 }), |
| 55 } | 52 } |
| 56 | 53 |
| 57 Convey("Bad", func() { | 54 Convey("Bad", func() { |
| 58 Convey("No such originating attempt", func() { | 55 Convey("No such originating attempt", func() { |
| 59 _, err := s.EnsureGraphData(c, req) | 56 _, err := s.EnsureGraphData(c, req) |
| 60 So(err, ShouldBeRPCUnauthenticated) | 57 So(err, ShouldBeRPCUnauthenticated) |
| 61 }) | 58 }) |
| 62 | 59 |
| 63 Convey("No such destination quest", func() { | 60 Convey("No such destination quest", func() { |
| 64 So(ds.Put(a, e), ShouldBeNil) | 61 So(ds.Put(a, e), ShouldBeNil) |
| 65 | 62 |
| 66 _, err := s.EnsureGraphData(c, req) | 63 _, err := s.EnsureGraphData(c, req) |
| 67 » » » » So(err, ShouldBeRPCInvalidArgument, `cannot crea
te attempts for absent quest "Q9SgH-f5kraxP_om80CdR9EmAvgmnUws_s5fvRmZiuc"`) | 64 » » » » So(err, ShouldBeRPCInvalidArgument, `cannot crea
te attempts for absent quest "FwcLo7vH7d24_mnsKIyKswk3NSezONOAKuDZwHrgl7M"`) |
| 68 }) | 65 }) |
| 69 }) | 66 }) |
| 70 | 67 |
| 71 Convey("Good", func() { | 68 Convey("Good", func() { |
| 72 So(ds.Put(a, e, toQuest), ShouldBeNil) | 69 So(ds.Put(a, e, toQuest), ShouldBeNil) |
| 73 | 70 |
| 74 Convey("deps already exist", func() { | 71 Convey("deps already exist", func() { |
| 75 So(ds.Put(fwd, to), ShouldBeNil) | 72 So(ds.Put(fwd, to), ShouldBeNil) |
| 76 | 73 |
| 77 rsp, err := s.EnsureGraphData(c, req) | 74 rsp, err := s.EnsureGraphData(c, req) |
| 78 So(err, ShouldBeNil) | 75 So(err, ShouldBeNil) |
| 79 » » » » purgeTimestamps(rsp.Result) | 76 » » » » rsp.Result.PurgeTimestamps() |
| 80 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ | 77 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ |
| 81 Accepted: true, | 78 Accepted: true, |
| 82 Result: &dm.GraphData{Quests: map[string
]*dm.Quest{ | 79 Result: &dm.GraphData{Quests: map[string
]*dm.Quest{ |
| 83 toQuest.ID: { | 80 toQuest.ID: { |
| 84 Data: &dm.Quest_Data{ | 81 Data: &dm.Quest_Data{ |
| 85 Desc: toQuest
Desc, | 82 Desc: toQuest
Desc, |
| 86 BuiltBy: []*dm.Q
uest_TemplateSpec{}, | 83 BuiltBy: []*dm.Q
uest_TemplateSpec{}, |
| 87 }, | 84 }, |
| 88 » » » » » » » Attempts: map[uint32]*dm
.Attempt{1: dm.NewAttemptNeedsExecution(zt)}, | 85 » » » » » » » Attempts: map[uint32]*dm
.Attempt{1: dm.NewAttemptScheduling()}, |
| 89 }, | 86 }, |
| 90 }}, | 87 }}, |
| 91 }) | 88 }) |
| 92 }) | 89 }) |
| 93 | 90 |
| 94 Convey("deps already done", func() { | 91 Convey("deps already done", func() { |
| 95 to.State = dm.Attempt_FINISHED | 92 to.State = dm.Attempt_FINISHED |
| 96 So(ds.Put(to), ShouldBeNil) | 93 So(ds.Put(to), ShouldBeNil) |
| 97 | 94 |
| 98 rsp, err := s.EnsureGraphData(c, req) | 95 rsp, err := s.EnsureGraphData(c, req) |
| 99 So(err, ShouldBeNil) | 96 So(err, ShouldBeNil) |
| 100 » » » » purgeTimestamps(rsp.Result) | 97 » » » » rsp.Result.PurgeTimestamps() |
| 101 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ | 98 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ |
| 102 Accepted: true, | 99 Accepted: true, |
| 103 Result: &dm.GraphData{Quests: map[string
]*dm.Quest{ | 100 Result: &dm.GraphData{Quests: map[string
]*dm.Quest{ |
| 104 toQuest.ID: { | 101 toQuest.ID: { |
| 105 Data: &dm.Quest_Data{ | 102 Data: &dm.Quest_Data{ |
| 106 Desc: toQuest
Desc, | 103 Desc: toQuest
Desc, |
| 107 BuiltBy: []*dm.Q
uest_TemplateSpec{}, | 104 BuiltBy: []*dm.Q
uest_TemplateSpec{}, |
| 108 }, | 105 }, |
| 109 » » » » » » » Attempts: map[uint32]*dm
.Attempt{1: dm.NewAttemptFinished(zt, 0, "")}, | 106 » » » » » » » Attempts: map[uint32]*dm
.Attempt{1: dm.NewAttemptFinished(zt, 0, "", nil)}, |
| 110 }, | 107 }, |
| 111 }}, | 108 }}, |
| 112 }) | 109 }) |
| 113 | 110 |
| 114 So(ds.Get(fwd), ShouldBeNil) | 111 So(ds.Get(fwd), ShouldBeNil) |
| 115 }) | 112 }) |
| 116 | 113 |
| 117 Convey("adding new deps", func() { | 114 Convey("adding new deps", func() { |
| 118 So(ds.Put(&model.Quest{ID: "to"}), ShouldBeNil) | 115 So(ds.Put(&model.Quest{ID: "to"}), ShouldBeNil) |
| 119 | 116 |
| 120 rsp, err := s.EnsureGraphData(c, req) | 117 rsp, err := s.EnsureGraphData(c, req) |
| 121 So(err, ShouldBeNil) | 118 So(err, ShouldBeNil) |
| 122 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{S
houldHalt: true}) | 119 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{S
houldHalt: true}) |
| 123 | 120 |
| 124 So(ds.Get(fwd), ShouldBeNil) | 121 So(ds.Get(fwd), ShouldBeNil) |
| 125 So(ds.Get(a), ShouldBeNil) | 122 So(ds.Get(a), ShouldBeNil) |
| 126 » » » » So(a.State, ShouldEqual, dm.Attempt_ADDING_DEPS) | 123 » » » » So(a.State, ShouldEqual, dm.Attempt_EXECUTING) |
| 124 » » » » So(ds.Get(e), ShouldBeNil) |
| 125 » » » » So(e.State, ShouldEqual, dm.Execution_STOPPING) |
| 127 }) | 126 }) |
| 128 | 127 |
| 129 }) | 128 }) |
| 130 }) | 129 }) |
| 131 } | 130 } |
| OLD | NEW |