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

Unified Diff: go/src/infra/gae/libs/gae/memory/taskqueue_test.go

Issue 1222903002: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: more fixes 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 side-by-side diff with in-line comments
Download patch
Index: go/src/infra/gae/libs/gae/memory/taskqueue_test.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/taskqueue_test.go b/go/src/infra/gae/libs/gae/memory/taskqueue_test.go
similarity index 78%
rename from go/src/infra/gae/libs/wrapper/memory/taskqueue_test.go
rename to go/src/infra/gae/libs/gae/memory/taskqueue_test.go
index 9009b2141ee993cdd13bcc4f207b2337d99efa10..be7e495d4aecf0afefbd3e407a2482bab0a80a6e 100644
--- a/go/src/infra/gae/libs/wrapper/memory/taskqueue_test.go
+++ b/go/src/infra/gae/libs/gae/memory/taskqueue_test.go
@@ -6,9 +6,7 @@ package memory
import (
"fmt"
- "infra/gae/libs/wrapper"
- "infra/libs/clock"
- "infra/libs/clock/testclock"
+ "infra/gae/libs/gae"
"math/rand"
"net/http"
"testing"
@@ -17,7 +15,8 @@ import (
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/net/context"
- "appengine/taskqueue"
+ "github.com/luci/luci-go/common/clock"
+ "github.com/luci/luci-go/common/clock/testclock"
)
func TestTaskQueue(t *testing.T) {
@@ -26,37 +25,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 = wrapper.SetMathRand(c, rand.New(rand.NewSource(clock.Now(c).UnixNano())))
+ c = gae.SetMathRand(c, rand.New(rand.NewSource(clock.Now(c).UnixNano())))
c = Use(c)
- tq := wrapper.GetTQ(c).(interface {
- wrapper.TQMultiReadWriter
- wrapper.TQTestable
+ tq := gae.GetTQ(c).(interface {
+ gae.TQMultiReadWriter
+ gae.TQTestable
})
So(tq, ShouldNotBeNil)
Convey("implements TQMultiReadWriter", func() {
Convey("Add", func() {
- t := &taskqueue.Task{Path: "/hello/world"}
+ t := &gae.TQTask{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 = &taskqueue.RetryOptions{AgeLimit: 7 * time.Second}
+ t.RetryOptions = &gae.TQRetryOptions{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, taskqueue.Task{
+ So(*tq.GetScheduledTasks()["default"][name], ShouldResemble, gae.TQTask{
ETA: now.Add(4 * time.Second),
Header: http.Header{"Cat": []string{"tabby"}},
Method: "POST",
Name: name,
Path: "/hello/world",
Payload: []byte("watwatwat"),
- RetryOptions: &taskqueue.RetryOptions{AgeLimit: 7 * time.Second},
+ RetryOptions: &gae.TQRetryOptions{AgeLimit: 7 * time.Second},
})
})
@@ -89,7 +88,7 @@ func TestTaskQueue(t *testing.T) {
// can't add the same one twice!
_, err = tq.Add(t, "")
- So(err, ShouldEqual, taskqueue.ErrTaskAlreadyAdded)
+ So(err, ShouldEqual, gae.ErrTQTaskAlreadyAdded)
})
Convey("cannot add deleted task", func() {
@@ -102,7 +101,7 @@ func TestTaskQueue(t *testing.T) {
// can't add a deleted task!
_, err = tq.Add(t, "")
- So(err, ShouldEqual, taskqueue.ErrTaskAlreadyAdded)
+ So(err, ShouldEqual, gae.ErrTQTaskAlreadyAdded)
})
Convey("cannot set ETA+Delay", func() {
@@ -145,7 +144,7 @@ func TestTaskQueue(t *testing.T) {
t2 := dupTask(t)
t2.Path = "/hi/city"
- expect := []*taskqueue.Task{t, t2}
+ expect := []*gae.TQTask{t, t2}
tasks, err := tq.AddMulti(expect, "default")
So(err, ShouldBeNil)
@@ -165,20 +164,20 @@ func TestTaskQueue(t *testing.T) {
Convey("can be broken", func() {
tq.BreakFeatures(nil, "AddMulti")
- _, err := tq.AddMulti([]*taskqueue.Task{t}, "")
+ _, err := tq.AddMulti([]*gae.TQTask{t}, "")
So(err.Error(), ShouldContainSubstring, "TRANSIENT_ERROR")
})
Convey("is not broken by Add", func() {
tq.BreakFeatures(nil, "Add")
- _, err := tq.AddMulti([]*taskqueue.Task{t}, "")
+ _, err := tq.AddMulti([]*gae.TQTask{t}, "")
So(err, ShouldBeNil)
})
})
})
Convey("Delete", func() {
- t := &taskqueue.Task{Path: "/hello/world"}
+ t := &gae.TQTask{Path: "/hello/world"}
tEnQ, err := tq.Add(t, "")
So(err, ShouldBeNil)
@@ -232,7 +231,7 @@ func TestTaskQueue(t *testing.T) {
So(err, ShouldBeNil)
Convey("usually works", func() {
- err = tq.DeleteMulti([]*taskqueue.Task{tEnQ, tEnQ2}, "")
+ err = tq.DeleteMulti([]*gae.TQTask{tEnQ, tEnQ2}, "")
So(err, ShouldBeNil)
So(len(tq.GetScheduledTasks()["default"]), ShouldEqual, 0)
So(len(tq.GetTombstonedTasks()["default"]), ShouldEqual, 2)
@@ -240,13 +239,13 @@ func TestTaskQueue(t *testing.T) {
Convey("can be broken", func() {
tq.BreakFeatures(nil, "DeleteMulti")
- err = tq.DeleteMulti([]*taskqueue.Task{tEnQ, tEnQ2}, "")
+ err = tq.DeleteMulti([]*gae.TQTask{tEnQ, tEnQ2}, "")
So(err.Error(), ShouldContainSubstring, "TRANSIENT_ERROR")
})
Convey("is not broken by Delete", func() {
tq.BreakFeatures(nil, "Delete")
- err = tq.DeleteMulti([]*taskqueue.Task{tEnQ, tEnQ2}, "")
+ err = tq.DeleteMulti([]*gae.TQTask{tEnQ, tEnQ2}, "")
So(err, ShouldBeNil)
})
})
@@ -254,11 +253,11 @@ func TestTaskQueue(t *testing.T) {
})
Convey("works with transactions", func() {
- t := &taskqueue.Task{Path: "/hello/world"}
+ t := &gae.TQTask{Path: "/hello/world"}
tEnQ, err := tq.Add(t, "")
So(err, ShouldBeNil)
- t2 := &taskqueue.Task{Path: "/hi/city"}
+ t2 := &gae.TQTask{Path: "/hi/city"}
tEnQ2, err := tq.Add(t2, "")
So(err, ShouldBeNil)
@@ -266,10 +265,10 @@ func TestTaskQueue(t *testing.T) {
So(err, ShouldBeNil)
Convey("can view regular tasks", func() {
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- tq := wrapper.GetTQ(c).(interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ tq := gae.GetTQ(c).(interface {
+ gae.TQTestable
+ gae.TaskQueue
})
So(tq.GetScheduledTasks()["default"][tEnQ.Name], ShouldResemble, tEnQ)
@@ -280,15 +279,15 @@ func TestTaskQueue(t *testing.T) {
})
Convey("can add a new task", func() {
- tEnQ3 := (*taskqueue.Task)(nil)
+ tEnQ3 := (*gae.TQTask)(nil)
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- tq := wrapper.GetTQ(c).(interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ tq := gae.GetTQ(c).(interface {
+ gae.TQTestable
+ gae.TaskQueue
})
- t3 := &taskqueue.Task{Path: "/sandwitch/victory"}
+ t3 := &gae.TQTask{Path: "/sandwitch/victory"}
tEnQ3, err = tq.Add(t3, "")
So(err, ShouldBeNil)
@@ -314,20 +313,20 @@ func TestTaskQueue(t *testing.T) {
})
Convey("can a new task (but reset the state in a test)", func() {
- tEnQ3 := (*taskqueue.Task)(nil)
+ tEnQ3 := (*gae.TQTask)(nil)
ttq := interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.TQTestable
+ gae.TaskQueue
}(nil)
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- ttq = wrapper.GetTQ(c).(interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ ttq = gae.GetTQ(c).(interface {
+ gae.TQTestable
+ gae.TaskQueue
})
- t3 := &taskqueue.Task{Path: "/sandwitch/victory"}
+ t3 := &gae.TQTask{Path: "/sandwitch/victory"}
tEnQ3, err = ttq.Add(t3, "")
So(err, ShouldBeNil)
@@ -355,12 +354,12 @@ func TestTaskQueue(t *testing.T) {
})
Convey("you can AddMulti as well", func() {
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- tq := wrapper.GetTQ(c).(interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ tq := gae.GetTQ(c).(interface {
+ gae.TQTestable
+ gae.TaskQueue
})
- _, err := tq.AddMulti([]*taskqueue.Task{t, t, t}, "")
+ _, err := tq.AddMulti([]*gae.TQTask{t, t, t}, "")
So(err, ShouldBeNil)
So(len(tq.GetScheduledTasks()["default"]), ShouldEqual, 1)
So(len(tq.GetTransactionTasks()["default"]), ShouldEqual, 3)
@@ -371,25 +370,25 @@ func TestTaskQueue(t *testing.T) {
})
Convey("unless you add too many things", func() {
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
for i := 0; i < 5; i++ {
- _, err = wrapper.GetTQ(c).Add(t, "")
+ _, err = gae.GetTQ(c).Add(t, "")
So(err, ShouldBeNil)
}
- _, err = wrapper.GetTQ(c).Add(t, "")
+ _, err = gae.GetTQ(c).Add(t, "")
So(err.Error(), ShouldContainSubstring, "BAD_REQUEST")
return nil
}, nil)
})
Convey("unless you Add to a bad queue", func() {
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- _, err = wrapper.GetTQ(c).Add(t, "meat")
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ _, err = gae.GetTQ(c).Add(t, "meat")
So(err.Error(), ShouldContainSubstring, "UNKNOWN_QUEUE")
Convey("unless you add it!", func() {
- wrapper.GetTQ(c).(wrapper.TQTestable).CreateQueue("meat")
- _, err = wrapper.GetTQ(c).Add(t, "meat")
+ gae.GetTQ(c).(gae.TQTestable).CreateQueue("meat")
+ _, err = gae.GetTQ(c).Add(t, "meat")
So(err, ShouldBeNil)
})
@@ -399,8 +398,8 @@ func TestTaskQueue(t *testing.T) {
Convey("unless Add is broken", func() {
tq.BreakFeatures(nil, "Add")
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- _, err = wrapper.GetTQ(c).Add(t, "")
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ _, err = gae.GetTQ(c).Add(t, "")
So(err.Error(), ShouldContainSubstring, "TRANSIENT_ERROR")
return nil
}, nil)
@@ -408,8 +407,8 @@ func TestTaskQueue(t *testing.T) {
Convey("unless AddMulti is broken", func() {
tq.BreakFeatures(nil, "AddMulti")
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- _, err = wrapper.GetTQ(c).AddMulti(nil, "")
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ _, err = gae.GetTQ(c).AddMulti(nil, "")
So(err.Error(), ShouldContainSubstring, "TRANSIENT_ERROR")
return nil
}, nil)
@@ -419,8 +418,8 @@ func TestTaskQueue(t *testing.T) {
err := error(nil)
func() {
defer func() { err = recover().(error) }()
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- wrapper.GetTQ(c).Delete(t, "")
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ gae.GetTQ(c).Delete(t, "")
return nil
}, nil)
}()
@@ -428,9 +427,9 @@ func TestTaskQueue(t *testing.T) {
})
Convey("adding a new task only happens if we don't errout", func() {
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- t3 := &taskqueue.Task{Path: "/sandwitch/victory"}
- _, err = wrapper.GetTQ(c).Add(t3, "")
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ t3 := &gae.TQTask{Path: "/sandwitch/victory"}
+ _, err = gae.GetTQ(c).Add(t3, "")
So(err, ShouldBeNil)
return fmt.Errorf("nooooo")
}, nil)
@@ -443,13 +442,13 @@ func TestTaskQueue(t *testing.T) {
Convey("likewise, a panic doesn't schedule anything", func() {
func() {
defer func() { recover() }()
- wrapper.GetDS(c).RunInTransaction(func(c context.Context) error {
- tq := wrapper.GetTQ(c).(interface {
- wrapper.TQTestable
- wrapper.TaskQueue
+ gae.GetRDS(c).RunInTransaction(func(c context.Context) error {
+ tq := gae.GetTQ(c).(interface {
+ gae.TQTestable
+ gae.TaskQueue
})
- t3 := &taskqueue.Task{Path: "/sandwitch/victory"}
+ t3 := &gae.TQTask{Path: "/sandwitch/victory"}
_, err = tq.Add(t3, "")
So(err, ShouldBeNil)

Powered by Google App Engine
This is Rietveld 408576698