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

Side by Side Diff: appengine/cmd/dm/deps/ensure_quests_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/clock" 14 "github.com/luci/luci-go/common/clock"
16 "github.com/luci/luci-go/common/clock/testclock" 15 "github.com/luci/luci-go/common/clock/testclock"
17 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
18 ) 17 )
19 18
20 func TestEnsureQuests(t *testing.T) { 19 func TestEnsureQuests(t *testing.T) {
21 t.Parallel() 20 t.Parallel()
22 21
23 desc := func(payload string) *dm.Quest_Desc { 22 desc := func(payload string) *dm.Quest_Desc {
24 return &dm.Quest_Desc{ 23 return &dm.Quest_Desc{
25 » » » DistributorConfigName: "foof", 24 » » » DistributorConfigName: "fakeDistributor",
26 JsonPayload: payload, 25 JsonPayload: payload,
27 } 26 }
28 } 27 }
29 28
30 Convey("EnsureGraphData (Ensure Quests)", t, func() { 29 Convey("EnsureGraphData (Ensure Quests)", t, func() {
31 » » ttest := &tumble.Testing{} 30 » » ttest, c, _, s := testSetup()
32 » » c := ttest.Context()
33 ds := datastore.Get(c) 31 ds := datastore.Get(c)
34 clk := clock.Get(c).(testclock.TestClock) 32 clk := clock.Get(c).(testclock.TestClock)
35 s := newDecoratedDeps()
36 zt := time.Time{}
37 33
38 Convey("bad", func() { 34 Convey("bad", func() {
39 // TODO(riannucci): restore this once moving to the new distributor scheme 35 // TODO(riannucci): restore this once moving to the new distributor scheme
40 /* 36 /*
41 Convey("missing distributor", func() { 37 Convey("missing distributor", func() {
42 _, err := s.EnsureQuests(c, &dm.EnsureQu estsReq{ 38 _, err := s.EnsureQuests(c, &dm.EnsureQu estsReq{
43 ToEnsure: []*dm.Quest_Desc{desc( "{}")}, 39 ToEnsure: []*dm.Quest_Desc{desc( "{}")},
44 }) 40 })
45 So(err, ShouldErrLike, "unknown distribu tors") 41 So(err, ShouldErrLike, "unknown distribu tors")
46 }) 42 })
47 */ 43 */
48 }) 44 })
49 45
50 Convey("good", func() { 46 Convey("good", func() {
51 » » » // TODO(riannucci): add foof distributor configuration 47 » » » // TODO(riannucci): add fakeDistributor distributor conf iguration
52 48
53 qd := desc(`{"data": "yes"}`) 49 qd := desc(`{"data": "yes"}`)
54 » » » q, err := model.NewQuest(c, qd) 50 » » » So(qd.Normalize(), ShouldBeNil)
55 » » » So(err, ShouldBeNil) 51 » » » q := model.NewQuest(c, qd)
56 52
57 qd2 := desc(`{"data": "way yes"}`) 53 qd2 := desc(`{"data": "way yes"}`)
58 » » » q2, err := model.NewQuest(c, qd2) 54 » » » So(qd2.Normalize(), ShouldBeNil)
59 » » » So(err, ShouldBeNil) 55 » » » q2 := model.NewQuest(c, qd2)
60 56
61 req := &dm.EnsureGraphDataReq{ 57 req := &dm.EnsureGraphDataReq{
62 Quest: []*dm.Quest_Desc{qd, qd2}, 58 Quest: []*dm.Quest_Desc{qd, qd2},
63 Attempts: dm.NewAttemptList(map[string][]uint32{ q.ID: {1}, q2.ID: {2}})} 59 Attempts: dm.NewAttemptList(map[string][]uint32{ q.ID: {1}, q2.ID: {2}})}
64 60
65 Convey("0/2 exist", func() { 61 Convey("0/2 exist", func() {
66 rsp, err := s.EnsureGraphData(c, req) 62 rsp, err := s.EnsureGraphData(c, req)
67 So(err, ShouldBeNil) 63 So(err, ShouldBeNil)
68 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{ 64 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{
69 q.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{1: {DNE: true}}}, 65 q.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{1: {DNE: true}}},
70 q2.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{2: {DNE: true}}}, 66 q2.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{2: {DNE: true}}},
71 }) 67 })
72 ttest.Drain(c) 68 ttest.Drain(c)
73 rsp, err = s.EnsureGraphData(c, req) 69 rsp, err = s.EnsureGraphData(c, req)
74 So(err, ShouldBeNil) 70 So(err, ShouldBeNil)
75 » » » » purgeTimestamps(rsp.Result) 71 » » » » rsp.Result.PurgeTimestamps()
76 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{ 72 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{
77 q.ID: { 73 q.ID: {
78 Data: &dm.Quest_Data{ 74 Data: &dm.Quest_Data{
79 Desc: qd, 75 Desc: qd,
80 BuiltBy: []*dm.Quest_Tem plateSpec{}, 76 BuiltBy: []*dm.Quest_Tem plateSpec{},
81 }, 77 },
82 » » » » » » Attempts: map[uint32]*dm.Attempt {1: dm.NewAttemptNeedsExecution(zt)}}, 78 » » » » » » Attempts: map[uint32]*dm.Attempt {1: dm.NewAttemptExecuting(1)}},
83 q2.ID: { 79 q2.ID: {
84 Data: &dm.Quest_Data{ 80 Data: &dm.Quest_Data{
85 Desc: qd2, 81 Desc: qd2,
86 BuiltBy: []*dm.Quest_Tem plateSpec{}, 82 BuiltBy: []*dm.Quest_Tem plateSpec{},
87 }, 83 },
88 » » » » » » Attempts: map[uint32]*dm.Attempt {2: dm.NewAttemptNeedsExecution(zt)}}, 84 » » » » » » Attempts: map[uint32]*dm.Attempt {2: dm.NewAttemptExecuting(1)}},
89 }) 85 })
90 }) 86 })
91 87
92 Convey("1/2 exist", func() { 88 Convey("1/2 exist", func() {
93 So(ds.Put(q), ShouldBeNil) 89 So(ds.Put(q), ShouldBeNil)
94 90
95 clk.Add(time.Minute) 91 clk.Add(time.Minute)
96 92
97 rsp, err := s.EnsureGraphData(c, req) 93 rsp, err := s.EnsureGraphData(c, req)
98 So(err, ShouldBeNil) 94 So(err, ShouldBeNil)
99 » » » » purgeTimestamps(rsp.Result) 95 » » » » rsp.Result.PurgeTimestamps()
100 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{ 96 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{
101 q.ID: { 97 q.ID: {
102 Data: &dm.Quest_Data{ 98 Data: &dm.Quest_Data{
103 Desc: qd, 99 Desc: qd,
104 BuiltBy: []*dm.Quest_Tem plateSpec{}, 100 BuiltBy: []*dm.Quest_Tem plateSpec{},
105 }, 101 },
106 Attempts: map[uint32]*dm.Attempt {1: {DNE: true}}, 102 Attempts: map[uint32]*dm.Attempt {1: {DNE: true}},
107 }, 103 },
108 q2.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{2: {DNE: true}}}, 104 q2.ID: {DNE: true, Attempts: map[uint32] *dm.Attempt{2: {DNE: true}}},
109 }) 105 })
110 now := clk.Now() 106 now := clk.Now()
111 ttest.Drain(c) 107 ttest.Drain(c)
112 108
113 qNew := &model.Quest{ID: q.ID} 109 qNew := &model.Quest{ID: q.ID}
114 So(ds.Get(qNew), ShouldBeNil) 110 So(ds.Get(qNew), ShouldBeNil)
115 So(qNew.Created, ShouldResemble, q.Created) 111 So(qNew.Created, ShouldResemble, q.Created)
116 112
117 q2New := &model.Quest{ID: q2.ID} 113 q2New := &model.Quest{ID: q2.ID}
118 So(ds.Get(q2New), ShouldBeNil) 114 So(ds.Get(q2New), ShouldBeNil)
119 So(q2New.Created, ShouldResemble, now.Round(time .Microsecond)) 115 So(q2New.Created, ShouldResemble, now.Round(time .Microsecond))
120 }) 116 })
121 117
122 Convey("all exist", func() { 118 Convey("all exist", func() {
123 So(ds.Put(q), ShouldBeNil) 119 So(ds.Put(q), ShouldBeNil)
124 So(ds.Put(q2), ShouldBeNil) 120 So(ds.Put(q2), ShouldBeNil)
125 121
126 rsp, err := s.EnsureGraphData(c, req) 122 rsp, err := s.EnsureGraphData(c, req)
127 So(err, ShouldBeNil) 123 So(err, ShouldBeNil)
128 » » » » purgeTimestamps(rsp.Result) 124 » » » » rsp.Result.PurgeTimestamps()
129 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{ 125 So(rsp.Result.Quests, ShouldResemble, map[string ]*dm.Quest{
130 q.ID: { 126 q.ID: {
131 Data: &dm.Quest_Data{ 127 Data: &dm.Quest_Data{
132 Desc: qd, 128 Desc: qd,
133 BuiltBy: []*dm.Quest_Tem plateSpec{}, 129 BuiltBy: []*dm.Quest_Tem plateSpec{},
134 }, 130 },
135 Attempts: map[uint32]*dm.Attempt {1: {DNE: true}}}, 131 Attempts: map[uint32]*dm.Attempt {1: {DNE: true}}},
136 q2.ID: { 132 q2.ID: {
137 Data: &dm.Quest_Data{ 133 Data: &dm.Quest_Data{
138 Desc: qd2, 134 Desc: qd2,
139 BuiltBy: []*dm.Quest_Tem plateSpec{}, 135 BuiltBy: []*dm.Quest_Tem plateSpec{},
140 }, 136 },
141 Attempts: map[uint32]*dm.Attempt {2: {DNE: true}}}, 137 Attempts: map[uint32]*dm.Attempt {2: {DNE: true}}},
142 }) 138 })
143 139
144 qNew := &model.Quest{ID: q.ID} 140 qNew := &model.Quest{ID: q.ID}
145 So(ds.Get(qNew), ShouldBeNil) 141 So(ds.Get(qNew), ShouldBeNil)
146 So(qNew.Created, ShouldResemble, q.Created) 142 So(qNew.Created, ShouldResemble, q.Created)
147 }) 143 })
148 }) 144 })
149 }) 145 })
150 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698