| Index: impl/memory/taskqueue_test.go
|
| diff --git a/memory/taskqueue_test.go b/impl/memory/taskqueue_test.go
|
| similarity index 81%
|
| rename from memory/taskqueue_test.go
|
| rename to impl/memory/taskqueue_test.go
|
| index 817a93f665c3bd2dc4a459eeaf66a3e5f13b9656..c1456be23dada9694952c875796545fe4c699e1e 100644
|
| --- a/memory/taskqueue_test.go
|
| +++ b/impl/memory/taskqueue_test.go
|
| @@ -11,9 +11,11 @@ import (
|
| "testing"
|
| "time"
|
|
|
| - "github.com/luci/gae"
|
| + rdsS "github.com/luci/gae/service/rawdatastore"
|
| + tqS "github.com/luci/gae/service/taskqueue"
|
| "github.com/luci/luci-go/common/clock"
|
| "github.com/luci/luci-go/common/clock/testclock"
|
| + "github.com/luci/luci-go/common/mathrand"
|
| . "github.com/smartystreets/goconvey/convey"
|
| "golang.org/x/net/context"
|
| )
|
| @@ -24,37 +26,37 @@ func TestTaskQueue(t *testing.T) {
|
| Convey("TaskQueue", t, func() {
|
| now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC)
|
| c, tc := testclock.UseTime(context.Background(), now)
|
| - c = gae.SetMathRand(c, rand.New(rand.NewSource(clock.Now(c).UnixNano())))
|
| + c = mathrand.Set(c, rand.New(rand.NewSource(clock.Now(c).UnixNano())))
|
| c = Use(c)
|
|
|
| - tq := gae.GetTQ(c).(interface {
|
| - gae.TaskQueue
|
| - gae.TQTestable
|
| + tq := tqS.Get(c).(interface {
|
| + tqS.Interface
|
| + tqS.Testable
|
| })
|
|
|
| So(tq, ShouldNotBeNil)
|
|
|
| Convey("implements TQMultiReadWriter", func() {
|
| Convey("Add", func() {
|
| - t := &gae.TQTask{Path: "/hello/world"}
|
| + t := &tqS.Task{Path: "/hello/world"}
|
|
|
| Convey("works", func() {
|
| t.Delay = 4 * time.Second
|
| t.Header = http.Header{}
|
| t.Header.Add("Cat", "tabby")
|
| t.Payload = []byte("watwatwat")
|
| - t.RetryOptions = &gae.TQRetryOptions{AgeLimit: 7 * time.Second}
|
| + t.RetryOptions = &tqS.RetryOptions{AgeLimit: 7 * time.Second}
|
| _, err := tq.Add(t, "")
|
| So(err, ShouldBeNil)
|
| name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGoay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZWyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZjXUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff"
|
| - So(*tq.GetScheduledTasks()["default"][name], ShouldResemble, gae.TQTask{
|
| + So(*tq.GetScheduledTasks()["default"][name], ShouldResemble, tqS.Task{
|
| ETA: now.Add(4 * time.Second),
|
| Header: http.Header{"Cat": []string{"tabby"}},
|
| Method: "POST",
|
| Name: name,
|
| Path: "/hello/world",
|
| Payload: []byte("watwatwat"),
|
| - RetryOptions: &gae.TQRetryOptions{AgeLimit: 7 * time.Second},
|
| + RetryOptions: &tqS.RetryOptions{AgeLimit: 7 * time.Second},
|
| })
|
| })
|
|
|
| @@ -87,7 +89,7 @@ func TestTaskQueue(t *testing.T) {
|
|
|
| // can't add the same one twice!
|
| _, err = tq.Add(t, "")
|
| - So(err, ShouldEqual, gae.ErrTQTaskAlreadyAdded)
|
| + So(err, ShouldEqual, tqS.ErrTaskAlreadyAdded)
|
| })
|
|
|
| Convey("cannot add deleted task", func() {
|
| @@ -100,7 +102,7 @@ func TestTaskQueue(t *testing.T) {
|
|
|
| // can't add a deleted task!
|
| _, err = tq.Add(t, "")
|
| - So(err, ShouldEqual, gae.ErrTQTaskAlreadyAdded)
|
| + So(err, ShouldEqual, tqS.ErrTaskAlreadyAdded)
|
| })
|
|
|
| Convey("cannot set ETA+Delay", func() {
|
| @@ -137,7 +139,7 @@ func TestTaskQueue(t *testing.T) {
|
| t2 := dupTask(t)
|
| t2.Path = "/hi/city"
|
|
|
| - expect := []*gae.TQTask{t, t2}
|
| + expect := []*tqS.Task{t, t2}
|
|
|
| tasks, err := tq.AddMulti(expect, "default")
|
| So(err, ShouldBeNil)
|
| @@ -158,7 +160,7 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("Delete", func() {
|
| - t := &gae.TQTask{Path: "/hello/world"}
|
| + t := &tqS.Task{Path: "/hello/world"}
|
| tEnQ, err := tq.Add(t, "")
|
| So(err, ShouldBeNil)
|
|
|
| @@ -206,7 +208,7 @@ func TestTaskQueue(t *testing.T) {
|
| So(err, ShouldBeNil)
|
|
|
| Convey("usually works", func() {
|
| - err = tq.DeleteMulti([]*gae.TQTask{tEnQ, tEnQ2}, "")
|
| + err = tq.DeleteMulti([]*tqS.Task{tEnQ, tEnQ2}, "")
|
| So(err, ShouldBeNil)
|
| So(len(tq.GetScheduledTasks()["default"]), ShouldEqual, 0)
|
| So(len(tq.GetTombstonedTasks()["default"]), ShouldEqual, 2)
|
| @@ -216,11 +218,11 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("works with transactions", func() {
|
| - t := &gae.TQTask{Path: "/hello/world"}
|
| + t := &tqS.Task{Path: "/hello/world"}
|
| tEnQ, err := tq.Add(t, "")
|
| So(err, ShouldBeNil)
|
|
|
| - t2 := &gae.TQTask{Path: "/hi/city"}
|
| + t2 := &tqS.Task{Path: "/hi/city"}
|
| tEnQ2, err := tq.Add(t2, "")
|
| So(err, ShouldBeNil)
|
|
|
| @@ -228,10 +230,10 @@ func TestTaskQueue(t *testing.T) {
|
| So(err, ShouldBeNil)
|
|
|
| Convey("can view regular tasks", func() {
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - tq := gae.GetTQ(c).(interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + tq := tqS.Get(c).(interface {
|
| + tqS.Testable
|
| + tqS.Interface
|
| })
|
|
|
| So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ)
|
| @@ -242,15 +244,15 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("can add a new task", func() {
|
| - tEnQ3 := (*gae.TQTask)(nil)
|
| + tEnQ3 := (*tqS.Task)(nil)
|
|
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - tq := gae.GetTQ(c).(interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + tq := tqS.Get(c).(interface {
|
| + tqS.Testable
|
| + tqS.Interface
|
| })
|
|
|
| - t3 := &gae.TQTask{Path: "/sandwitch/victory"}
|
| + t3 := &tqS.Task{Path: "/sandwitch/victory"}
|
| tEnQ3, err = tq.Add(t3, "")
|
| So(err, ShouldBeNil)
|
|
|
| @@ -276,20 +278,20 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("can a new task (but reset the state in a test)", func() {
|
| - tEnQ3 := (*gae.TQTask)(nil)
|
| + tEnQ3 := (*tqS.Task)(nil)
|
|
|
| ttq := interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + tqS.Testable
|
| + tqS.Interface
|
| }(nil)
|
|
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - ttq = gae.GetTQ(c).(interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + ttq = tqS.Get(c).(interface {
|
| + tqS.Testable
|
| + tqS.Interface
|
| })
|
|
|
| - t3 := &gae.TQTask{Path: "/sandwitch/victory"}
|
| + t3 := &tqS.Task{Path: "/sandwitch/victory"}
|
| tEnQ3, err = ttq.Add(t3, "")
|
| So(err, ShouldBeNil)
|
|
|
| @@ -317,12 +319,12 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("you can AddMulti as well", func() {
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - tq := gae.GetTQ(c).(interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + tq := tqS.Get(c).(interface {
|
| + tqS.Testable
|
| + tqS.Interface
|
| })
|
| - _, err := tq.AddMulti([]*gae.TQTask{t, t, t}, "")
|
| + _, err := tq.AddMulti([]*tqS.Task{t, t, t}, "")
|
| So(err, ShouldBeNil)
|
| So(len(tq.GetScheduledTasks()["default"]), ShouldEqual, 1)
|
| So(len(tq.GetTransactionTasks()["default"]), ShouldEqual, 3)
|
| @@ -333,25 +335,25 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("unless you add too many things", func() {
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| for i := 0; i < 5; i++ {
|
| - _, err = gae.GetTQ(c).Add(t, "")
|
| + _, err = tqS.Get(c).Add(t, "")
|
| So(err, ShouldBeNil)
|
| }
|
| - _, err = gae.GetTQ(c).Add(t, "")
|
| + _, err = tqS.Get(c).Add(t, "")
|
| So(err.Error(), ShouldContainSubstring, "BAD_REQUEST")
|
| return nil
|
| }, nil)
|
| })
|
|
|
| Convey("unless you Add to a bad queue", func() {
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - _, err = gae.GetTQ(c).Add(t, "meat")
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + _, err = tqS.Get(c).Add(t, "meat")
|
| So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE")
|
|
|
| Convey("unless you add it!", func() {
|
| - gae.GetTQ(c).(gae.TQTestable).CreateQueue("meat")
|
| - _, err = gae.GetTQ(c).Add(t, "meat")
|
| + tqS.Get(c).(tqS.Testable).CreateQueue("meat")
|
| + _, err = tqS.Get(c).Add(t, "meat")
|
| So(err, ShouldBeNil)
|
| })
|
|
|
| @@ -363,8 +365,8 @@ func TestTaskQueue(t *testing.T) {
|
| err := error(nil)
|
| func() {
|
| defer func() { err = recover().(error) }()
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - gae.GetTQ(c).Delete(t, "")
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + tqS.Get(c).Delete(t, "")
|
| return nil
|
| }, nil)
|
| }()
|
| @@ -372,9 +374,9 @@ func TestTaskQueue(t *testing.T) {
|
| })
|
|
|
| Convey("adding a new task only happens if we don't errout", func() {
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - t3 := &gae.TQTask{Path: "/sandwitch/victory"}
|
| - _, err = gae.GetTQ(c).Add(t3, "")
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + t3 := &tqS.Task{Path: "/sandwitch/victory"}
|
| + _, err = tqS.Get(c).Add(t3, "")
|
| So(err, ShouldBeNil)
|
| return fmt.Errorf("nooooo")
|
| }, nil)
|
| @@ -387,13 +389,13 @@ func TestTaskQueue(t *testing.T) {
|
| Convey("likewise, a panic doesn't schedule anything", func() {
|
| func() {
|
| defer func() { recover() }()
|
| - gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
|
| - tq := gae.GetTQ(c).(interface {
|
| - gae.TQTestable
|
| - gae.TaskQueue
|
| + rdsS.Get(c).RunInTransaction(func(c context.Context) error {
|
| + tq := tqS.Get(c).(interface {
|
| + tqS.Testable
|
| + tqS.Interface
|
| })
|
|
|
| - t3 := &gae.TQTask{Path: "/sandwitch/victory"}
|
| + t3 := &tqS.Task{Path: "/sandwitch/victory"}
|
| _, err = tq.Add(t3, "")
|
| So(err, ShouldBeNil)
|
|
|
|
|