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

Side by Side Diff: appengine/cmd/dm/model/attempt_test.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file 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
« no previous file with comments | « appengine/cmd/dm/model/attempt.go ('k') | appengine/cmd/dm/model/execution.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 model 5 package model
6 6
7 import ( 7 import (
8 "math" 8 "math"
9 "testing" 9 "testing"
10 "time" 10 "time"
(...skipping 12 matching lines...) Expand all
23 23
24 func TestAttempt(t *testing.T) { 24 func TestAttempt(t *testing.T) {
25 t.Parallel() 25 t.Parallel()
26 26
27 Convey("Attempt", t, func() { 27 Convey("Attempt", t, func() {
28 c := context.Background() 28 c := context.Background()
29 c, clk := testclock.UseTime(c, testclock.TestTimeUTC) 29 c, clk := testclock.UseTime(c, testclock.TestTimeUTC)
30 30
31 Convey("ModifyState", func() { 31 Convey("ModifyState", func() {
32 a := MakeAttempt(c, dm.NewAttemptID("quest", 5)) 32 a := MakeAttempt(c, dm.NewAttemptID("quest", 5))
33 » » » So(a.State, ShouldEqual, dm.Attempt_NEEDS_EXECUTION) 33 » » » So(a.State, ShouldEqual, dm.Attempt_SCHEDULING)
34 » » » So(a.ModifyState(c, dm.Attempt_ADDING_DEPS), ShouldErrLi ke, "invalid state transition") 34 » » » So(a.ModifyState(c, dm.Attempt_FINISHED), ShouldErrLike, "invalid state transition")
35 So(a.Modified, ShouldResemble, testclock.TestTimeUTC) 35 So(a.Modified, ShouldResemble, testclock.TestTimeUTC)
36 36
37 clk.Add(time.Second) 37 clk.Add(time.Second)
38 38
39 So(a.ModifyState(c, dm.Attempt_EXECUTING), ShouldBeNil) 39 So(a.ModifyState(c, dm.Attempt_EXECUTING), ShouldBeNil)
40 So(a.State, ShouldEqual, dm.Attempt_EXECUTING) 40 So(a.State, ShouldEqual, dm.Attempt_EXECUTING)
41 So(a.Modified, ShouldResemble, clk.Now()) 41 So(a.Modified, ShouldResemble, clk.Now())
42 42
43 » » » So(a.ModifyState(c, dm.Attempt_ADDING_DEPS), ShouldBeNil ) 43 » » » So(a.ModifyState(c, dm.Attempt_WAITING), ShouldBeNil)
44 » » » So(a.ModifyState(c, dm.Attempt_BLOCKED), ShouldBeNil) 44 » » » So(a.ModifyState(c, dm.Attempt_WAITING), ShouldBeNil)
45 » » » So(a.ModifyState(c, dm.Attempt_BLOCKED), ShouldBeNil) 45 » » » So(a.ModifyState(c, dm.Attempt_SCHEDULING), ShouldBeNil)
46 » » » So(a.ModifyState(c, dm.Attempt_NEEDS_EXECUTION), ShouldB eNil)
47 So(a.ModifyState(c, dm.Attempt_EXECUTING), ShouldBeNil) 46 So(a.ModifyState(c, dm.Attempt_EXECUTING), ShouldBeNil)
48 So(a.ModifyState(c, dm.Attempt_FINISHED), ShouldBeNil) 47 So(a.ModifyState(c, dm.Attempt_FINISHED), ShouldBeNil)
49 48
50 » » » So(a.ModifyState(c, dm.Attempt_NEEDS_EXECUTION), ShouldE rrLike, "invalid") 49 » » » So(a.ModifyState(c, dm.Attempt_SCHEDULING), ShouldErrLik e, "invalid")
51 So(a.State, ShouldEqual, dm.Attempt_FINISHED) 50 So(a.State, ShouldEqual, dm.Attempt_FINISHED)
52 }) 51 })
53 52
54 Convey("ToProto", func() { 53 Convey("ToProto", func() {
55 Convey("NeedsExecution", func() { 54 Convey("NeedsExecution", func() {
56 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) ) 55 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) )
57 56
58 » » » » So(a.ToProto(true), ShouldResemble, &dm.Attempt{ 57 » » » » atmpt := dm.NewAttemptScheduling()
59 » » » » » Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0}, 58 » » » » atmpt.Id = dm.NewAttemptID("quest", 10)
60 » » » » » Data: &dm.Attempt_Data{ 59 » » » » atmpt.Data.Created = google_pb.NewTimestamp(test clock.TestTimeUTC)
61 » » » » » » Created: google_pb.NewTime stamp(testclock.TestTimeUTC), 60 » » » » atmpt.Data.Modified = google_pb.NewTimestamp(tes tclock.TestTimeUTC)
62 » » » » » » Modified: google_pb.NewTime stamp(testclock.TestTimeUTC), 61
63 » » » » » » NumExecutions: 0, 62 » » » » So(a.ToProto(true), ShouldResemble, atmpt)
64 » » » » » » AttemptType: &dm.Attempt_Data_Ne edsExecution_{NeedsExecution: &dm.Attempt_Data_NeedsExecution{
65 » » » » » » » Pending: google_pb.NewTi mestamp(testclock.TestTimeUTC)}},
66 » » » » » },
67 » » » » })
68 }) 63 })
69 64
70 Convey("Executing", func() { 65 Convey("Executing", func() {
71 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) ) 66 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) )
72 clk.Add(10 * time.Second) 67 clk.Add(10 * time.Second)
73 a.CurExecution = 1 68 a.CurExecution = 1
74 So(a.ModifyState(c, dm.Attempt_EXECUTING), Shoul dBeNil) 69 So(a.ModifyState(c, dm.Attempt_EXECUTING), Shoul dBeNil)
75 70
76 So(a.ToProto(true), ShouldResemble, &dm.Attempt{ 71 So(a.ToProto(true), ShouldResemble, &dm.Attempt{
77 Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0}, 72 Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0},
78 Data: &dm.Attempt_Data{ 73 Data: &dm.Attempt_Data{
79 Created: google_pb.NewTime stamp(testclock.TestTimeUTC), 74 Created: google_pb.NewTime stamp(testclock.TestTimeUTC),
80 Modified: google_pb.NewTime stamp(clk.Now()), 75 Modified: google_pb.NewTime stamp(clk.Now()),
81 NumExecutions: 1, 76 NumExecutions: 1,
82 AttemptType: &dm.Attempt_Data_Ex ecuting_{Executing: &dm.Attempt_Data_Executing{ 77 AttemptType: &dm.Attempt_Data_Ex ecuting_{Executing: &dm.Attempt_Data_Executing{
83 CurExecutionId: 1}}}, 78 CurExecutionId: 1}}},
84 }) 79 })
85 }) 80 })
86 81
87 » » » Convey("AddingDeps", func() { 82 » » » Convey("Waiting", func() {
88 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) ) 83 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) )
89 clk.Add(10 * time.Second) 84 clk.Add(10 * time.Second)
90 a.CurExecution = 1 85 a.CurExecution = 1
91 So(a.ModifyState(c, dm.Attempt_EXECUTING), Shoul dBeNil) 86 So(a.ModifyState(c, dm.Attempt_EXECUTING), Shoul dBeNil)
92 clk.Add(10 * time.Second) 87 clk.Add(10 * time.Second)
93 » » » » So(a.ModifyState(c, dm.Attempt_ADDING_DEPS), Sho uldBeNil) 88 » » » » So(a.ModifyState(c, dm.Attempt_WAITING), ShouldB eNil)
94 » » » » a.AddingDepsBitmap = bf.Make(4) 89 » » » » a.DepMap = bf.Make(4)
95 » » » » a.AddingDepsBitmap.Set(1) 90 » » » » a.DepMap.Set(2)
96 » » » » a.AddingDepsBitmap.Set(3)
97 » » » » a.WaitingDepBitmap = bf.Make(4)
98 91
99 » » » » So(a.ToProto(true), ShouldResemble, &dm.Attempt{ 92 » » » » atmpt := dm.NewAttemptWaiting(3)
100 » » » » » Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0}, 93 » » » » atmpt.Id = dm.NewAttemptID("quest", 10)
101 » » » » » Data: &dm.Attempt_Data{ 94 » » » » atmpt.Data.Created = google_pb.NewTimestamp(test clock.TestTimeUTC)
102 » » » » » » Created: google_pb.NewTime stamp(testclock.TestTimeUTC), 95 » » » » atmpt.Data.Modified = google_pb.NewTimestamp(clk .Now())
103 » » » » » » Modified: google_pb.NewTime stamp(clk.Now()), 96 » » » » atmpt.Data.NumExecutions = 1
104 » » » » » » NumExecutions: 1,
105 » » » » » » AttemptType: &dm.Attempt_Data_Ad dingDeps_{AddingDeps: &dm.Attempt_Data_AddingDeps{
106 » » » » » » » NumAdding: 2,
107 » » » » » » » NumWaiting: 4}}},
108 » » » » })
109 » » » })
110 97
111 » » » Convey("Blocked", func() { 98 » » » » So(a.ToProto(true), ShouldResemble, atmpt)
112 » » » » a := MakeAttempt(c, dm.NewAttemptID("quest", 10) )
113 » » » » clk.Add(10 * time.Second)
114 » » » » a.CurExecution = 1
115 » » » » So(a.ModifyState(c, dm.Attempt_EXECUTING), Shoul dBeNil)
116 » » » » clk.Add(10 * time.Second)
117 » » » » So(a.ModifyState(c, dm.Attempt_ADDING_DEPS), Sho uldBeNil)
118 » » » » a.WaitingDepBitmap = bf.Make(4)
119 » » » » a.WaitingDepBitmap.Set(2)
120 » » » » // don't increment the time: let the automatic m icrosecond advancement
121 » » » » // take effect.
122 » » » » So(a.ModifyState(c, dm.Attempt_BLOCKED), ShouldB eNil)
123
124 » » » » So(a.ToProto(true), ShouldResemble, &dm.Attempt{
125 » » » » » Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0},
126 » » » » » Data: &dm.Attempt_Data{
127 » » » » » » Created: google_pb.NewTime stamp(testclock.TestTimeUTC),
128 » » » » » » Modified: google_pb.NewTime stamp(clk.Now().Add(time.Microsecond)),
129 » » » » » » NumExecutions: 1,
130 » » » » » » AttemptType: &dm.Attempt_Data_Bl ocked_{Blocked: &dm.Attempt_Data_Blocked{
131 » » » » » » » NumWaiting: 3}}},
132 » » » » })
133 }) 99 })
134 100
135 Convey("Finished", func() { 101 Convey("Finished", func() {
136 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) ) 102 a := MakeAttempt(c, dm.NewAttemptID("quest", 10) )
137 a.State = dm.Attempt_FINISHED 103 a.State = dm.Attempt_FINISHED
138 a.CurExecution = math.MaxUint32 104 a.CurExecution = math.MaxUint32
139 » » » » a.AddingDepsBitmap = bf.Make(20) 105 » » » » a.DepMap = bf.Make(20)
140 » » » » a.WaitingDepBitmap = bf.Make(20)
141 a.ResultExpiration = testclock.TestTimeUTC.Add(1 0 * time.Second) 106 a.ResultExpiration = testclock.TestTimeUTC.Add(1 0 * time.Second)
142 107
143 » » » » a.WaitingDepBitmap.Set(1) 108 » » » » a.DepMap.Set(1)
144 » » » » a.WaitingDepBitmap.Set(5) 109 » » » » a.DepMap.Set(5)
145 » » » » a.WaitingDepBitmap.Set(7) 110 » » » » a.DepMap.Set(7)
146 111
147 So(a.ToProto(true), ShouldResemble, &dm.Attempt{ 112 So(a.ToProto(true), ShouldResemble, &dm.Attempt{
148 Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0}, 113 Id: &dm.Attempt_ID{Quest: "quest", Id: 1 0},
149 Data: &dm.Attempt_Data{ 114 Data: &dm.Attempt_Data{
150 Created: google_pb.NewTime stamp(testclock.TestTimeUTC), 115 Created: google_pb.NewTime stamp(testclock.TestTimeUTC),
151 Modified: google_pb.NewTime stamp(testclock.TestTimeUTC), 116 Modified: google_pb.NewTime stamp(testclock.TestTimeUTC),
152 NumExecutions: math.MaxUint32, 117 NumExecutions: math.MaxUint32,
153 AttemptType: &dm.Attempt_Data_Fi nished_{Finished: &dm.Attempt_Data_Finished{ 118 AttemptType: &dm.Attempt_Data_Fi nished_{Finished: &dm.Attempt_Data_Finished{
154 Expiration: google_pb.Ne wTimestamp(testclock.TestTimeUTC.Add(10 * time.Second))}}, 119 Expiration: google_pb.Ne wTimestamp(testclock.TestTimeUTC.Add(10 * time.Second))}},
155 }, 120 },
156 }) 121 })
157 }) 122 })
158 }) 123 })
159 }) 124 })
160 } 125 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/model/attempt.go ('k') | appengine/cmd/dm/model/execution.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698