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

Side by Side Diff: impl/memory/taskqueue_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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 | « impl/memory/taskqueue_data.go ('k') | impl/memory/testing_utils_test.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 Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "math/rand" 9 "math/rand"
10 "net/http" 10 "net/http"
11 "testing" 11 "testing"
12 "time" 12 "time"
13 13
14 » "github.com/luci/gae" 14 » rdsS "github.com/luci/gae/service/rawdatastore"
15 » tqS "github.com/luci/gae/service/taskqueue"
15 "github.com/luci/luci-go/common/clock" 16 "github.com/luci/luci-go/common/clock"
16 "github.com/luci/luci-go/common/clock/testclock" 17 "github.com/luci/luci-go/common/clock/testclock"
18 "github.com/luci/luci-go/common/mathrand"
17 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
18 "golang.org/x/net/context" 20 "golang.org/x/net/context"
19 ) 21 )
20 22
21 func TestTaskQueue(t *testing.T) { 23 func TestTaskQueue(t *testing.T) {
22 t.Parallel() 24 t.Parallel()
23 25
24 Convey("TaskQueue", t, func() { 26 Convey("TaskQueue", t, func() {
25 now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC) 27 now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC)
26 c, tc := testclock.UseTime(context.Background(), now) 28 c, tc := testclock.UseTime(context.Background(), now)
27 » » c = gae.SetMathRand(c, rand.New(rand.NewSource(clock.Now(c).Unix Nano()))) 29 » » c = mathrand.Set(c, rand.New(rand.NewSource(clock.Now(c).UnixNan o())))
28 c = Use(c) 30 c = Use(c)
29 31
30 » » tq := gae.GetTQ(c).(interface { 32 » » tq := tqS.Get(c).(interface {
31 » » » gae.TaskQueue 33 » » » tqS.Interface
32 » » » gae.TQTestable 34 » » » tqS.Testable
33 }) 35 })
34 36
35 So(tq, ShouldNotBeNil) 37 So(tq, ShouldNotBeNil)
36 38
37 Convey("implements TQMultiReadWriter", func() { 39 Convey("implements TQMultiReadWriter", func() {
38 Convey("Add", func() { 40 Convey("Add", func() {
39 » » » » t := &gae.TQTask{Path: "/hello/world"} 41 » » » » t := &tqS.Task{Path: "/hello/world"}
40 42
41 Convey("works", func() { 43 Convey("works", func() {
42 t.Delay = 4 * time.Second 44 t.Delay = 4 * time.Second
43 t.Header = http.Header{} 45 t.Header = http.Header{}
44 t.Header.Add("Cat", "tabby") 46 t.Header.Add("Cat", "tabby")
45 t.Payload = []byte("watwatwat") 47 t.Payload = []byte("watwatwat")
46 » » » » » t.RetryOptions = &gae.TQRetryOptions{Age Limit: 7 * time.Second} 48 » » » » » t.RetryOptions = &tqS.RetryOptions{AgeLi mit: 7 * time.Second}
47 _, err := tq.Add(t, "") 49 _, err := tq.Add(t, "")
48 So(err, ShouldBeNil) 50 So(err, ShouldBeNil)
49 name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5 CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o 4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGo ay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZ WyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZj XUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff" 51 name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5 CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o 4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGo ay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZ WyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZj XUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff"
50 » » » » » So(*tq.GetScheduledTasks()["default"][na me], ShouldResemble, gae.TQTask{ 52 » » » » » So(*tq.GetScheduledTasks()["default"][na me], ShouldResemble, tqS.Task{
51 ETA: now.Add(4 * time.S econd), 53 ETA: now.Add(4 * time.S econd),
52 Header: http.Header{"Cat": []string{"tabby"}}, 54 Header: http.Header{"Cat": []string{"tabby"}},
53 Method: "POST", 55 Method: "POST",
54 Name: name, 56 Name: name,
55 Path: "/hello/world", 57 Path: "/hello/world",
56 Payload: []byte("watwatwat" ), 58 Payload: []byte("watwatwat" ),
57 » » » » » » RetryOptions: &gae.TQRetryOption s{AgeLimit: 7 * time.Second}, 59 » » » » » » RetryOptions: &tqS.RetryOptions{ AgeLimit: 7 * time.Second},
58 }) 60 })
59 }) 61 })
60 62
61 Convey("cannot add to bad queues", func() { 63 Convey("cannot add to bad queues", func() {
62 _, err := tq.Add(nil, "waaat") 64 _, err := tq.Add(nil, "waaat")
63 So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE") 65 So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE")
64 66
65 Convey("but you can add Queues when test ing", func() { 67 Convey("but you can add Queues when test ing", func() {
66 tq.CreateQueue("waaat") 68 tq.CreateQueue("waaat")
67 _, err := tq.Add(t, "waaat") 69 _, err := tq.Add(t, "waaat")
(...skipping 12 matching lines...) Expand all
80 So(tr.Path, ShouldEqual, "/_ah/queue/def ault") 82 So(tr.Path, ShouldEqual, "/_ah/queue/def ault")
81 }) 83 })
82 84
83 Convey("cannot add twice", func() { 85 Convey("cannot add twice", func() {
84 t.Name = "bob" 86 t.Name = "bob"
85 _, err := tq.Add(t, "") 87 _, err := tq.Add(t, "")
86 So(err, ShouldBeNil) 88 So(err, ShouldBeNil)
87 89
88 // can't add the same one twice! 90 // can't add the same one twice!
89 _, err = tq.Add(t, "") 91 _, err = tq.Add(t, "")
90 » » » » » So(err, ShouldEqual, gae.ErrTQTaskAlread yAdded) 92 » » » » » So(err, ShouldEqual, tqS.ErrTaskAlreadyA dded)
91 }) 93 })
92 94
93 Convey("cannot add deleted task", func() { 95 Convey("cannot add deleted task", func() {
94 t.Name = "bob" 96 t.Name = "bob"
95 _, err := tq.Add(t, "") 97 _, err := tq.Add(t, "")
96 So(err, ShouldBeNil) 98 So(err, ShouldBeNil)
97 99
98 err = tq.Delete(t, "") 100 err = tq.Delete(t, "")
99 So(err, ShouldBeNil) 101 So(err, ShouldBeNil)
100 102
101 // can't add a deleted task! 103 // can't add a deleted task!
102 _, err = tq.Add(t, "") 104 _, err = tq.Add(t, "")
103 » » » » » So(err, ShouldEqual, gae.ErrTQTaskAlread yAdded) 105 » » » » » So(err, ShouldEqual, tqS.ErrTaskAlreadyA dded)
104 }) 106 })
105 107
106 Convey("cannot set ETA+Delay", func() { 108 Convey("cannot set ETA+Delay", func() {
107 t.ETA = clock.Now(c).Add(time.Hour) 109 t.ETA = clock.Now(c).Add(time.Hour)
108 tc.Add(time.Second) 110 tc.Add(time.Second)
109 t.Delay = time.Hour 111 t.Delay = time.Hour
110 So(func() { tq.Add(t, "") }, ShouldPanic ) 112 So(func() { tq.Add(t, "") }, ShouldPanic )
111 }) 113 })
112 114
113 Convey("must use a reasonable method", func() { 115 Convey("must use a reasonable method", func() {
(...skipping 16 matching lines...) Expand all
130 Convey("invalid names are rejected", func() { 132 Convey("invalid names are rejected", func() {
131 t.Name = "happy times" 133 t.Name = "happy times"
132 _, err := tq.Add(t, "") 134 _, err := tq.Add(t, "")
133 So(err.Error(), ShouldContainSubstring, "INVALID_TASK_NAME") 135 So(err.Error(), ShouldContainSubstring, "INVALID_TASK_NAME")
134 }) 136 })
135 137
136 Convey("AddMulti also works", func() { 138 Convey("AddMulti also works", func() {
137 t2 := dupTask(t) 139 t2 := dupTask(t)
138 t2.Path = "/hi/city" 140 t2.Path = "/hi/city"
139 141
140 » » » » » expect := []*gae.TQTask{t, t2} 142 » » » » » expect := []*tqS.Task{t, t2}
141 143
142 tasks, err := tq.AddMulti(expect, "defau lt") 144 tasks, err := tq.AddMulti(expect, "defau lt")
143 So(err, ShouldBeNil) 145 So(err, ShouldBeNil)
144 So(len(tasks), ShouldEqual, 2) 146 So(len(tasks), ShouldEqual, 2)
145 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 2) 147 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 2)
146 148
147 for i := range expect { 149 for i := range expect {
148 Convey(fmt.Sprintf("task %d: %s" , i, expect[i].Path), func() { 150 Convey(fmt.Sprintf("task %d: %s" , i, expect[i].Path), func() {
149 expect[i].Method = "POST " 151 expect[i].Method = "POST "
150 expect[i].ETA = now 152 expect[i].ETA = now
151 So(expect[i].Name, Shoul dEqual, "") 153 So(expect[i].Name, Shoul dEqual, "")
152 So(len(tasks[i].Name), S houldEqual, 500) 154 So(len(tasks[i].Name), S houldEqual, 500)
153 tasks[i].Name = "" 155 tasks[i].Name = ""
154 So(tasks[i], ShouldResem ble, expect[i]) 156 So(tasks[i], ShouldResem ble, expect[i])
155 }) 157 })
156 } 158 }
157 }) 159 })
158 }) 160 })
159 161
160 Convey("Delete", func() { 162 Convey("Delete", func() {
161 » » » » t := &gae.TQTask{Path: "/hello/world"} 163 » » » » t := &tqS.Task{Path: "/hello/world"}
162 tEnQ, err := tq.Add(t, "") 164 tEnQ, err := tq.Add(t, "")
163 So(err, ShouldBeNil) 165 So(err, ShouldBeNil)
164 166
165 Convey("works", func() { 167 Convey("works", func() {
166 t.Name = tEnQ.Name 168 t.Name = tEnQ.Name
167 err := tq.Delete(t, "") 169 err := tq.Delete(t, "")
168 So(err, ShouldBeNil) 170 So(err, ShouldBeNil)
169 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 0) 171 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 0)
170 So(len(tq.GetTombstonedTasks()["default" ]), ShouldEqual, 1) 172 So(len(tq.GetTombstonedTasks()["default" ]), ShouldEqual, 1)
171 So(tq.GetTombstonedTasks()["default"][tE nQ.Name], ShouldResemble, tEnQ) 173 So(tq.GetTombstonedTasks()["default"][tE nQ.Name], ShouldResemble, tEnQ)
(...skipping 27 matching lines...) Expand all
199 So(err.Error(), ShouldContainSubstring, "UNKNOWN_TASK") 201 So(err.Error(), ShouldContainSubstring, "UNKNOWN_TASK")
200 }) 202 })
201 203
202 Convey("DeleteMulti also works", func() { 204 Convey("DeleteMulti also works", func() {
203 t2 := dupTask(t) 205 t2 := dupTask(t)
204 t2.Path = "/hi/city" 206 t2.Path = "/hi/city"
205 tEnQ2, err := tq.Add(t2, "") 207 tEnQ2, err := tq.Add(t2, "")
206 So(err, ShouldBeNil) 208 So(err, ShouldBeNil)
207 209
208 Convey("usually works", func() { 210 Convey("usually works", func() {
209 » » » » » » err = tq.DeleteMulti([]*gae.TQTa sk{tEnQ, tEnQ2}, "") 211 » » » » » » err = tq.DeleteMulti([]*tqS.Task {tEnQ, tEnQ2}, "")
210 So(err, ShouldBeNil) 212 So(err, ShouldBeNil)
211 So(len(tq.GetScheduledTasks()["d efault"]), ShouldEqual, 0) 213 So(len(tq.GetScheduledTasks()["d efault"]), ShouldEqual, 0)
212 So(len(tq.GetTombstonedTasks()[" default"]), ShouldEqual, 2) 214 So(len(tq.GetTombstonedTasks()[" default"]), ShouldEqual, 2)
213 }) 215 })
214 }) 216 })
215 }) 217 })
216 }) 218 })
217 219
218 Convey("works with transactions", func() { 220 Convey("works with transactions", func() {
219 » » » t := &gae.TQTask{Path: "/hello/world"} 221 » » » t := &tqS.Task{Path: "/hello/world"}
220 tEnQ, err := tq.Add(t, "") 222 tEnQ, err := tq.Add(t, "")
221 So(err, ShouldBeNil) 223 So(err, ShouldBeNil)
222 224
223 » » » t2 := &gae.TQTask{Path: "/hi/city"} 225 » » » t2 := &tqS.Task{Path: "/hi/city"}
224 tEnQ2, err := tq.Add(t2, "") 226 tEnQ2, err := tq.Add(t2, "")
225 So(err, ShouldBeNil) 227 So(err, ShouldBeNil)
226 228
227 err = tq.Delete(tEnQ2, "") 229 err = tq.Delete(tEnQ2, "")
228 So(err, ShouldBeNil) 230 So(err, ShouldBeNil)
229 231
230 Convey("can view regular tasks", func() { 232 Convey("can view regular tasks", func() {
231 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 233 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
232 » » » » » tq := gae.GetTQ(c).(interface { 234 » » » » » tq := tqS.Get(c).(interface {
233 » » » » » » gae.TQTestable 235 » » » » » » tqS.Testable
234 » » » » » » gae.TaskQueue 236 » » » » » » tqS.Interface
235 }) 237 })
236 238
237 So(tq.GetScheduledTasks()["default"][tEn Q.Name], ShouldResemble, tEnQ) 239 So(tq.GetScheduledTasks()["default"][tEn Q.Name], ShouldResemble, tEnQ)
238 So(tq.GetTombstonedTasks()["default"][tE nQ2.Name], ShouldResemble, tEnQ2) 240 So(tq.GetTombstonedTasks()["default"][tE nQ2.Name], ShouldResemble, tEnQ2)
239 So(tq.GetTransactionTasks()["default"], ShouldBeNil) 241 So(tq.GetTransactionTasks()["default"], ShouldBeNil)
240 return nil 242 return nil
241 }, nil) 243 }, nil)
242 }) 244 })
243 245
244 Convey("can add a new task", func() { 246 Convey("can add a new task", func() {
245 » » » » tEnQ3 := (*gae.TQTask)(nil) 247 » » » » tEnQ3 := (*tqS.Task)(nil)
246 248
247 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 249 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
248 » » » » » tq := gae.GetTQ(c).(interface { 250 » » » » » tq := tqS.Get(c).(interface {
249 » » » » » » gae.TQTestable 251 » » » » » » tqS.Testable
250 » » » » » » gae.TaskQueue 252 » » » » » » tqS.Interface
251 }) 253 })
252 254
253 » » » » » t3 := &gae.TQTask{Path: "/sandwitch/vict ory"} 255 » » » » » t3 := &tqS.Task{Path: "/sandwitch/victor y"}
254 tEnQ3, err = tq.Add(t3, "") 256 tEnQ3, err = tq.Add(t3, "")
255 So(err, ShouldBeNil) 257 So(err, ShouldBeNil)
256 258
257 So(tq.GetScheduledTasks()["default"][tEn Q.Name], ShouldResemble, tEnQ) 259 So(tq.GetScheduledTasks()["default"][tEn Q.Name], ShouldResemble, tEnQ)
258 So(tq.GetTombstonedTasks()["default"][tE nQ2.Name], ShouldResemble, tEnQ2) 260 So(tq.GetTombstonedTasks()["default"][tE nQ2.Name], ShouldResemble, tEnQ2)
259 So(tq.GetTransactionTasks()["default"][0 ], ShouldResemble, tEnQ3) 261 So(tq.GetTransactionTasks()["default"][0 ], ShouldResemble, tEnQ3)
260 return nil 262 return nil
261 }, nil) 263 }, nil)
262 264
263 // name gets generated at transaction-commit-tim e 265 // name gets generated at transaction-commit-tim e
264 for name := range tq.GetScheduledTasks()["defaul t"] { 266 for name := range tq.GetScheduledTasks()["defaul t"] {
265 if name == tEnQ.Name { 267 if name == tEnQ.Name {
266 continue 268 continue
267 } 269 }
268 tEnQ3.Name = name 270 tEnQ3.Name = name
269 break 271 break
270 } 272 }
271 273
272 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ) 274 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ)
273 So(tq.GetScheduledTasks()["default"][tEnQ3.Name] , ShouldResemble, tEnQ3) 275 So(tq.GetScheduledTasks()["default"][tEnQ3.Name] , ShouldResemble, tEnQ3)
274 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2) 276 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2)
275 So(tq.GetTransactionTasks()["default"], ShouldBe Nil) 277 So(tq.GetTransactionTasks()["default"], ShouldBe Nil)
276 }) 278 })
277 279
278 Convey("can a new task (but reset the state in a test)", func() { 280 Convey("can a new task (but reset the state in a test)", func() {
279 » » » » tEnQ3 := (*gae.TQTask)(nil) 281 » » » » tEnQ3 := (*tqS.Task)(nil)
280 282
281 ttq := interface { 283 ttq := interface {
282 » » » » » gae.TQTestable 284 » » » » » tqS.Testable
283 » » » » » gae.TaskQueue 285 » » » » » tqS.Interface
284 }(nil) 286 }(nil)
285 287
286 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 288 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
287 » » » » » ttq = gae.GetTQ(c).(interface { 289 » » » » » ttq = tqS.Get(c).(interface {
288 » » » » » » gae.TQTestable 290 » » » » » » tqS.Testable
289 » » » » » » gae.TaskQueue 291 » » » » » » tqS.Interface
290 }) 292 })
291 293
292 » » » » » t3 := &gae.TQTask{Path: "/sandwitch/vict ory"} 294 » » » » » t3 := &tqS.Task{Path: "/sandwitch/victor y"}
293 tEnQ3, err = ttq.Add(t3, "") 295 tEnQ3, err = ttq.Add(t3, "")
294 So(err, ShouldBeNil) 296 So(err, ShouldBeNil)
295 297
296 So(ttq.GetScheduledTasks()["default"][tE nQ.Name], ShouldResemble, tEnQ) 298 So(ttq.GetScheduledTasks()["default"][tE nQ.Name], ShouldResemble, tEnQ)
297 So(ttq.GetTombstonedTasks()["default"][t EnQ2.Name], ShouldResemble, tEnQ2) 299 So(ttq.GetTombstonedTasks()["default"][t EnQ2.Name], ShouldResemble, tEnQ2)
298 So(ttq.GetTransactionTasks()["default"][ 0], ShouldResemble, tEnQ3) 300 So(ttq.GetTransactionTasks()["default"][ 0], ShouldResemble, tEnQ3)
299 301
300 ttq.ResetTasks() 302 ttq.ResetTasks()
301 303
302 So(len(ttq.GetScheduledTasks()["default" ]), ShouldEqual, 0) 304 So(len(ttq.GetScheduledTasks()["default" ]), ShouldEqual, 0)
303 So(len(ttq.GetTombstonedTasks()["default "]), ShouldEqual, 0) 305 So(len(ttq.GetTombstonedTasks()["default "]), ShouldEqual, 0)
304 So(len(ttq.GetTransactionTasks()["defaul t"]), ShouldEqual, 0) 306 So(len(ttq.GetTransactionTasks()["defaul t"]), ShouldEqual, 0)
305 307
306 return nil 308 return nil
307 }, nil) 309 }, nil)
308 310
309 So(len(tq.GetScheduledTasks()["default"]), Shoul dEqual, 0) 311 So(len(tq.GetScheduledTasks()["default"]), Shoul dEqual, 0)
310 So(len(tq.GetTombstonedTasks()["default"]), Shou ldEqual, 0) 312 So(len(tq.GetTombstonedTasks()["default"]), Shou ldEqual, 0)
311 So(len(tq.GetTransactionTasks()["default"]), Sho uldEqual, 0) 313 So(len(tq.GetTransactionTasks()["default"]), Sho uldEqual, 0)
312 314
313 Convey("and reusing a closed context is bad time s", func() { 315 Convey("and reusing a closed context is bad time s", func() {
314 _, err := ttq.Add(nil, "") 316 _, err := ttq.Add(nil, "")
315 So(err.Error(), ShouldContainSubstring, "expired") 317 So(err.Error(), ShouldContainSubstring, "expired")
316 }) 318 })
317 }) 319 })
318 320
319 Convey("you can AddMulti as well", func() { 321 Convey("you can AddMulti as well", func() {
320 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 322 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
321 » » » » » tq := gae.GetTQ(c).(interface { 323 » » » » » tq := tqS.Get(c).(interface {
322 » » » » » » gae.TQTestable 324 » » » » » » tqS.Testable
323 » » » » » » gae.TaskQueue 325 » » » » » » tqS.Interface
324 }) 326 })
325 » » » » » _, err := tq.AddMulti([]*gae.TQTask{t, t , t}, "") 327 » » » » » _, err := tq.AddMulti([]*tqS.Task{t, t, t}, "")
326 So(err, ShouldBeNil) 328 So(err, ShouldBeNil)
327 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 1) 329 So(len(tq.GetScheduledTasks()["default"] ), ShouldEqual, 1)
328 So(len(tq.GetTransactionTasks()["default "]), ShouldEqual, 3) 330 So(len(tq.GetTransactionTasks()["default "]), ShouldEqual, 3)
329 return nil 331 return nil
330 }, nil) 332 }, nil)
331 So(len(tq.GetScheduledTasks()["default"]), Shoul dEqual, 4) 333 So(len(tq.GetScheduledTasks()["default"]), Shoul dEqual, 4)
332 So(len(tq.GetTransactionTasks()["default"]), Sho uldEqual, 0) 334 So(len(tq.GetTransactionTasks()["default"]), Sho uldEqual, 0)
333 }) 335 })
334 336
335 Convey("unless you add too many things", func() { 337 Convey("unless you add too many things", func() {
336 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 338 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
337 for i := 0; i < 5; i++ { 339 for i := 0; i < 5; i++ {
338 » » » » » » _, err = gae.GetTQ(c).Add(t, "") 340 » » » » » » _, err = tqS.Get(c).Add(t, "")
339 So(err, ShouldBeNil) 341 So(err, ShouldBeNil)
340 } 342 }
341 » » » » » _, err = gae.GetTQ(c).Add(t, "") 343 » » » » » _, err = tqS.Get(c).Add(t, "")
342 So(err.Error(), ShouldContainSubstring, "BAD_REQUEST") 344 So(err.Error(), ShouldContainSubstring, "BAD_REQUEST")
343 return nil 345 return nil
344 }, nil) 346 }, nil)
345 }) 347 })
346 348
347 Convey("unless you Add to a bad queue", func() { 349 Convey("unless you Add to a bad queue", func() {
348 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 350 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
349 » » » » » _, err = gae.GetTQ(c).Add(t, "meat") 351 » » » » » _, err = tqS.Get(c).Add(t, "meat")
350 So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE") 352 So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE")
351 353
352 Convey("unless you add it!", func() { 354 Convey("unless you add it!", func() {
353 » » » » » » gae.GetTQ(c).(gae.TQTestable).Cr eateQueue("meat") 355 » » » » » » tqS.Get(c).(tqS.Testable).Create Queue("meat")
354 » » » » » » _, err = gae.GetTQ(c).Add(t, "me at") 356 » » » » » » _, err = tqS.Get(c).Add(t, "meat ")
355 So(err, ShouldBeNil) 357 So(err, ShouldBeNil)
356 }) 358 })
357 359
358 return nil 360 return nil
359 }, nil) 361 }, nil)
360 }) 362 })
361 363
362 Convey("No other features are available, however", func( ) { 364 Convey("No other features are available, however", func( ) {
363 err := error(nil) 365 err := error(nil)
364 func() { 366 func() {
365 defer func() { err = recover().(error) } () 367 defer func() { err = recover().(error) } ()
366 » » » » » gae.GetRDS(c).RunInTransaction(func(c co ntext.Context) error { 368 » » » » » rdsS.Get(c).RunInTransaction(func(c cont ext.Context) error {
367 » » » » » » gae.GetTQ(c).Delete(t, "") 369 » » » » » » tqS.Get(c).Delete(t, "")
368 return nil 370 return nil
369 }, nil) 371 }, nil)
370 }() 372 }()
371 So(err.Error(), ShouldContainSubstring, "TaskQue ue.Delete") 373 So(err.Error(), ShouldContainSubstring, "TaskQue ue.Delete")
372 }) 374 })
373 375
374 Convey("adding a new task only happens if we don't errou t", func() { 376 Convey("adding a new task only happens if we don't errou t", func() {
375 » » » » gae.GetRDS(c).RunInTransaction(func(c context.Co ntext) error { 377 » » » » rdsS.Get(c).RunInTransaction(func(c context.Cont ext) error {
376 » » » » » t3 := &gae.TQTask{Path: "/sandwitch/vict ory"} 378 » » » » » t3 := &tqS.Task{Path: "/sandwitch/victor y"}
377 » » » » » _, err = gae.GetTQ(c).Add(t3, "") 379 » » » » » _, err = tqS.Get(c).Add(t3, "")
378 So(err, ShouldBeNil) 380 So(err, ShouldBeNil)
379 return fmt.Errorf("nooooo") 381 return fmt.Errorf("nooooo")
380 }, nil) 382 }, nil)
381 383
382 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ) 384 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ)
383 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2) 385 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2)
384 So(tq.GetTransactionTasks()["default"], ShouldBe Nil) 386 So(tq.GetTransactionTasks()["default"], ShouldBe Nil)
385 }) 387 })
386 388
387 Convey("likewise, a panic doesn't schedule anything", fu nc() { 389 Convey("likewise, a panic doesn't schedule anything", fu nc() {
388 func() { 390 func() {
389 defer func() { recover() }() 391 defer func() { recover() }()
390 » » » » » gae.GetRDS(c).RunInTransaction(func(c co ntext.Context) error { 392 » » » » » rdsS.Get(c).RunInTransaction(func(c cont ext.Context) error {
391 » » » » » » tq := gae.GetTQ(c).(interface { 393 » » » » » » tq := tqS.Get(c).(interface {
392 » » » » » » » gae.TQTestable 394 » » » » » » » tqS.Testable
393 » » » » » » » gae.TaskQueue 395 » » » » » » » tqS.Interface
394 }) 396 })
395 397
396 » » » » » » t3 := &gae.TQTask{Path: "/sandwi tch/victory"} 398 » » » » » » t3 := &tqS.Task{Path: "/sandwitc h/victory"}
397 _, err = tq.Add(t3, "") 399 _, err = tq.Add(t3, "")
398 So(err, ShouldBeNil) 400 So(err, ShouldBeNil)
399 401
400 panic(fmt.Errorf("nooooo")) 402 panic(fmt.Errorf("nooooo"))
401 }, nil) 403 }, nil)
402 }() 404 }()
403 405
404 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ) 406 So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ)
405 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2) 407 So(tq.GetTombstonedTasks()["default"][tEnQ2.Name ], ShouldResemble, tEnQ2)
406 So(tq.GetTransactionTasks()["default"], ShouldBe Nil) 408 So(tq.GetTransactionTasks()["default"], ShouldBe Nil)
407 }) 409 })
408 410
409 }) 411 })
410 }) 412 })
411 } 413 }
OLDNEW
« no previous file with comments | « impl/memory/taskqueue_data.go ('k') | impl/memory/testing_utils_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698