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

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

Issue 2995493002: [impl/memory] Enforce named tasks during txn. (Closed)
Patch Set: Created 3 years, 4 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.go ('k') | no next file » | 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. 1 // Copyright 2015 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 So(tq.Add(c, "", tasks...), ShouldBeNil) 349 So(tq.Add(c, "", tasks...), ShouldBeNil)
350 So(len(tqt.GetScheduledTasks()["default" ]), ShouldEqual, 1) 350 So(len(tqt.GetScheduledTasks()["default" ]), ShouldEqual, 1)
351 So(len(tqt.GetTransactionTasks()["defaul t"]), ShouldEqual, 3) 351 So(len(tqt.GetTransactionTasks()["defaul t"]), ShouldEqual, 3)
352 return nil 352 return nil
353 }, nil), ShouldBeNil) 353 }, nil), ShouldBeNil)
354 So(len(tqt.GetScheduledTasks()["default"]), Shou ldEqual, 4) 354 So(len(tqt.GetScheduledTasks()["default"]), Shou ldEqual, 4)
355 So(len(tqt.GetTransactionTasks()["default"]), Sh ouldEqual, 0) 355 So(len(tqt.GetTransactionTasks()["default"]), Sh ouldEqual, 0)
356 }) 356 })
357 357
358 Convey("unless you add too many things", func() { 358 Convey("unless you add too many things", func() {
359 t.Name = ""
360
359 So(ds.RunInTransaction(c, func(c context.Context ) error { 361 So(ds.RunInTransaction(c, func(c context.Context ) error {
360 for i := 0; i < 5; i++ { 362 for i := 0; i < 5; i++ {
361 So(tq.Add(c, "", t.Duplicate()), ShouldBeNil) 363 So(tq.Add(c, "", t.Duplicate()), ShouldBeNil)
362 } 364 }
363 So(tq.Add(c, "", t).Error(), ShouldConta inSubstring, "BAD_REQUEST") 365 So(tq.Add(c, "", t).Error(), ShouldConta inSubstring, "BAD_REQUEST")
364 return nil 366 return nil
365 }, nil), ShouldBeNil) 367 }, nil), ShouldBeNil)
366 }) 368 })
367 369
368 Convey("unless you Add to a bad queue", func() { 370 Convey("unless you Add to a bad queue", func() {
371 t.Name = ""
372
369 So(ds.RunInTransaction(c, func(c context.Context ) error { 373 So(ds.RunInTransaction(c, func(c context.Context ) error {
370 So(tq.Add(c, "meat", t).Error(), ShouldC ontainSubstring, "UNKNOWN_QUEUE") 374 So(tq.Add(c, "meat", t).Error(), ShouldC ontainSubstring, "UNKNOWN_QUEUE")
371 375
372 Convey("unless you add it!", func() { 376 Convey("unless you add it!", func() {
373 tq.Raw(c).GetTestable().CreateQu eue("meat") 377 tq.Raw(c).GetTestable().CreateQu eue("meat")
374 So(tq.Add(c, "meat", t), ShouldB eNil) 378 So(tq.Add(c, "meat", t), ShouldB eNil)
375 }) 379 })
376 380
377 return nil 381 return nil
378 }, nil), ShouldBeNil) 382 }, nil), ShouldBeNil)
379 }) 383 })
380 384
385 Convey("unless the task is named", func() {
386 So(ds.RunInTransaction(c, func(c context.Context ) error {
387 err := tq.Add(c, "", t) // Note: "t" has a Name from initial Add.
388 So(err, ShouldNotBeNil)
389 So(err.Error(), ShouldContainSubstring, "INVALID_TASK_NAME")
390
391 return nil
392 }, nil), ShouldBeNil)
393 })
394
381 Convey("No other features are available, however", func( ) { 395 Convey("No other features are available, however", func( ) {
382 So(ds.RunInTransaction(c, func(c context.Context ) error { 396 So(ds.RunInTransaction(c, func(c context.Context ) error {
383 So(tq.Delete(c, "", t).Error(), ShouldCo ntainSubstring, "cannot DeleteMulti from a transaction") 397 So(tq.Delete(c, "", t).Error(), ShouldCo ntainSubstring, "cannot DeleteMulti from a transaction")
384 So(tq.Purge(c, "").Error(), ShouldContai nSubstring, "cannot Purge from a transaction") 398 So(tq.Purge(c, "").Error(), ShouldContai nSubstring, "cannot Purge from a transaction")
385 _, err := tq.Stats(c, "") 399 _, err := tq.Stats(c, "")
386 So(err.Error(), ShouldContainSubstring, "cannot Stats from a transaction") 400 So(err.Error(), ShouldContainSubstring, "cannot Stats from a transaction")
387 return nil 401 return nil
388 }, nil), ShouldBeNil) 402 }, nil), ShouldBeNil)
389 }) 403 })
390 404
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 leased, err := tq.LeaseByTag(c, 100, "pull", tim e.Minute, "") 979 leased, err := tq.LeaseByTag(c, 100, "pull", tim e.Minute, "")
966 So(err, ShouldBeNil) 980 So(err, ShouldBeNil)
967 So(len(leased), ShouldEqual, 5) 981 So(len(leased), ShouldEqual, 5)
968 for i := 0; i < 5; i++ { 982 for i := 0; i < 5; i++ {
969 So(leased[i].Name, ShouldEqual, fmt.Spri ntf("task-%d", i)) 983 So(leased[i].Name, ShouldEqual, fmt.Spri ntf("task-%d", i))
970 } 984 }
971 }) 985 })
972 }) 986 })
973 }) 987 })
974 } 988 }
OLDNEW
« no previous file with comments | « impl/memory/taskqueue.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698