Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: appengine/cmd/dm/deps/add_deps_test.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.PutMulti([]interface{}{a, e}), ShouldBeNil ) 61 So(ds.PutMulti([]interface{}{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.PutMulti([]interface{}{a, e, toQuest}), ShouldBeNi l) 69 So(ds.PutMulti([]interface{}{a, e, toQuest}), ShouldBeNi l)
73 70
74 Convey("deps already exist", func() { 71 Convey("deps already exist", func() {
75 So(ds.Put(fwd), ShouldBeNil) 72 So(ds.Put(fwd), ShouldBeNil)
76 So(ds.Put(to), ShouldBeNil) 73 So(ds.Put(to), ShouldBeNil)
77 74
78 rsp, err := s.EnsureGraphData(c, req) 75 rsp, err := s.EnsureGraphData(c, req)
79 So(err, ShouldBeNil) 76 So(err, ShouldBeNil)
80 » » » » purgeTimestamps(rsp.Result) 77 » » » » rsp.Result.PurgeTimestamps()
81 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ 78 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{
82 Accepted: true, 79 Accepted: true,
83 Result: &dm.GraphData{Quests: map[string ]*dm.Quest{ 80 Result: &dm.GraphData{Quests: map[string ]*dm.Quest{
84 toQuest.ID: { 81 toQuest.ID: {
85 Data: &dm.Quest_Data{ 82 Data: &dm.Quest_Data{
86 Desc: toQuest Desc, 83 Desc: toQuest Desc,
87 BuiltBy: []*dm.Q uest_TemplateSpec{}, 84 BuiltBy: []*dm.Q uest_TemplateSpec{},
88 }, 85 },
89 » » » » » » » Attempts: map[uint32]*dm .Attempt{1: dm.NewAttemptNeedsExecution(zt)}, 86 » » » » » » » Attempts: map[uint32]*dm .Attempt{1: dm.NewAttemptScheduling()},
90 }, 87 },
91 }}, 88 }},
92 }) 89 })
93 }) 90 })
94 91
95 Convey("deps already done", func() { 92 Convey("deps already done", func() {
96 to.State = dm.Attempt_FINISHED 93 to.State = dm.Attempt_FINISHED
97 So(ds.Put(to), ShouldBeNil) 94 So(ds.Put(to), ShouldBeNil)
98 95
99 rsp, err := s.EnsureGraphData(c, req) 96 rsp, err := s.EnsureGraphData(c, req)
100 So(err, ShouldBeNil) 97 So(err, ShouldBeNil)
101 » » » » purgeTimestamps(rsp.Result) 98 » » » » rsp.Result.PurgeTimestamps()
102 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{ 99 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{
103 Accepted: true, 100 Accepted: true,
104 Result: &dm.GraphData{Quests: map[string ]*dm.Quest{ 101 Result: &dm.GraphData{Quests: map[string ]*dm.Quest{
105 toQuest.ID: { 102 toQuest.ID: {
106 Data: &dm.Quest_Data{ 103 Data: &dm.Quest_Data{
107 Desc: toQuest Desc, 104 Desc: toQuest Desc,
108 BuiltBy: []*dm.Q uest_TemplateSpec{}, 105 BuiltBy: []*dm.Q uest_TemplateSpec{},
109 }, 106 },
110 » » » » » » » Attempts: map[uint32]*dm .Attempt{1: dm.NewAttemptFinished(zt, 0, "")}, 107 » » » » » » » Attempts: map[uint32]*dm .Attempt{1: dm.NewAttemptFinished(zt, 0, "", "")},
111 }, 108 },
112 }}, 109 }},
113 }) 110 })
114 111
115 So(ds.Get(fwd), ShouldBeNil) 112 So(ds.Get(fwd), ShouldBeNil)
116 }) 113 })
117 114
118 Convey("adding new deps", func() { 115 Convey("adding new deps", func() {
119 So(ds.Put(&model.Quest{ID: "to"}), ShouldBeNil) 116 So(ds.Put(&model.Quest{ID: "to"}), ShouldBeNil)
120 117
121 rsp, err := s.EnsureGraphData(c, req) 118 rsp, err := s.EnsureGraphData(c, req)
122 So(err, ShouldBeNil) 119 So(err, ShouldBeNil)
123 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{S houldHalt: true}) 120 So(rsp, ShouldResemble, &dm.EnsureGraphDataRsp{S houldHalt: true})
124 121
125 So(ds.Get(fwd), ShouldBeNil) 122 So(ds.Get(fwd), ShouldBeNil)
126 So(ds.Get(a), ShouldBeNil) 123 So(ds.Get(a), ShouldBeNil)
127 » » » » So(a.State, ShouldEqual, dm.Attempt_ADDING_DEPS) 124 » » » » So(a.State, ShouldEqual, dm.Attempt_EXECUTING)
125 » » » » So(ds.Get(e), ShouldBeNil)
126 » » » » So(e.State, ShouldEqual, dm.Execution_STOPPING)
128 }) 127 })
129 128
130 }) 129 })
131 }) 130 })
132 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698