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

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

Issue 1890983004: service/taskqueue: Add NewPOSTTask, remove NewTask (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 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 | « no previous file | service/taskqueue/interface.go » ('j') | service/taskqueue/types.go » ('J')
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"
(...skipping 21 matching lines...) Expand all
32 c = Use(c) 32 c = Use(c)
33 33
34 tq := tqS.Get(c) 34 tq := tqS.Get(c)
35 tqt := tq.Testable() 35 tqt := tq.Testable()
36 So(tqt, ShouldNotBeNil) 36 So(tqt, ShouldNotBeNil)
37 37
38 So(tq, ShouldNotBeNil) 38 So(tq, ShouldNotBeNil)
39 39
40 Convey("implements TQMultiReadWriter", func() { 40 Convey("implements TQMultiReadWriter", func() {
41 Convey("Add", func() { 41 Convey("Add", func() {
42 » » » » t := tq.NewTask("/hello/world") 42 » » » » t := &tqS.Task{Path: "/hello/world"}
43 43
44 Convey("works", func() { 44 Convey("works", func() {
45 t.Delay = 4 * time.Second 45 t.Delay = 4 * time.Second
46 t.Header = http.Header{} 46 t.Header = http.Header{}
47 t.Header.Add("Cat", "tabby") 47 t.Header.Add("Cat", "tabby")
48 t.Payload = []byte("watwatwat") 48 t.Payload = []byte("watwatwat")
49 t.RetryOptions = &tqS.RetryOptions{AgeLi mit: 7 * time.Second} 49 t.RetryOptions = &tqS.RetryOptions{AgeLi mit: 7 * time.Second}
50 So(tq.Add(t, ""), ShouldBeNil) 50 So(tq.Add(t, ""), ShouldBeNil)
51 51
52 name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5 CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o 4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGo ay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZ WyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZj XUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff" 52 name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5 CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o 4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGo ay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZ WyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZj XUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff"
53 So(tqt.GetScheduledTasks()["default"][na me], ShouldResemble, &tqS.Task{ 53 So(tqt.GetScheduledTasks()["default"][na me], ShouldResemble, &tqS.Task{
54 ETA: now.Add(4 * time.S econd), 54 ETA: now.Add(4 * time.S econd),
55 Header: http.Header{"Cat": []string{"tabby"}}, 55 Header: http.Header{"Cat": []string{"tabby"}},
56 Method: "POST", 56 Method: "POST",
57 Name: name, 57 Name: name,
58 Path: "/hello/world", 58 Path: "/hello/world",
59 Payload: []byte("watwatwat" ), 59 Payload: []byte("watwatwat" ),
60 RetryOptions: &tqS.RetryOptions{ AgeLimit: 7 * time.Second}, 60 RetryOptions: &tqS.RetryOptions{ AgeLimit: 7 * time.Second},
61 }) 61 })
62 }) 62 })
63 63
64 Convey("picks up namespace", func() { 64 Convey("picks up namespace", func() {
65 c, err := info.Get(c).Namespace("coolNam espace") 65 c, err := info.Get(c).Namespace("coolNam espace")
66 So(err, ShouldBeNil) 66 So(err, ShouldBeNil)
67 tq = tqS.Get(c) 67 tq = tqS.Get(c)
68 68
69 » » » » » t := tq.NewTask("") 69 » » » » » t := &tqS.Task{Path: ""}
iannucci 2016/04/16 01:26:43 Task{}
dnj 2016/04/16 01:50:26 Done.
70 So(tq.Add(t, ""), ShouldBeNil) 70 So(tq.Add(t, ""), ShouldBeNil)
71 So(t.Header, ShouldResemble, http.Header { 71 So(t.Header, ShouldResemble, http.Header {
72 "X-Appengine-Current-Namespace": {"coolNamespace"}, 72 "X-Appengine-Current-Namespace": {"coolNamespace"},
73 }) 73 })
74 74
75 }) 75 })
76 76
77 Convey("cannot add to bad queues", func() { 77 Convey("cannot add to bad queues", func() {
78 So(tq.Add(nil, "waaat").Error(), ShouldC ontainSubstring, "UNKNOWN_QUEUE") 78 So(tq.Add(nil, "waaat").Error(), ShouldC ontainSubstring, "UNKNOWN_QUEUE")
79 79
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 Convey(fmt.Sprintf("task %d: %s" , i, expect[i].Path), func() { 151 Convey(fmt.Sprintf("task %d: %s" , i, expect[i].Path), func() {
152 So(expect[i].Method, Sho uldEqual, "POST") 152 So(expect[i].Method, Sho uldEqual, "POST")
153 So(expect[i].ETA, Should HappenOnOrBefore, now) 153 So(expect[i].ETA, Should HappenOnOrBefore, now)
154 So(len(expect[i].Name), ShouldEqual, 500) 154 So(len(expect[i].Name), ShouldEqual, 500)
155 }) 155 })
156 } 156 }
157 157
158 Convey("stats work too", func() { 158 Convey("stats work too", func() {
159 delay := -time.Second * 400 159 delay := -time.Second * 400
160 160
161 » » » » » » t := tq.NewTask("/somewhere") 161 » » » » » » t := &tqS.Task{Path: "/somewhere "}
162 t.Delay = delay 162 t.Delay = delay
163 So(tq.Add(t, ""), ShouldBeNil) 163 So(tq.Add(t, ""), ShouldBeNil)
164 164
165 stats, err := tq.Stats("") 165 stats, err := tq.Stats("")
166 So(err, ShouldBeNil) 166 So(err, ShouldBeNil)
167 So(stats[0].Tasks, ShouldEqual, 3) 167 So(stats[0].Tasks, ShouldEqual, 3)
168 So(stats[0].OldestETA, ShouldHap penOnOrBefore, clock.Now(c).Add(delay)) 168 So(stats[0].OldestETA, ShouldHap penOnOrBefore, clock.Now(c).Add(delay))
169 169
170 _, err = tq.Stats("noexist") 170 _, err = tq.Stats("noexist")
171 So(err.Error(), ShouldContainSub string, "UNKNOWN_QUEUE") 171 So(err.Error(), ShouldContainSub string, "UNKNOWN_QUEUE")
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 So(tqS.GetNoTxn(c).Delete(t, ""), Should BeNil) 375 So(tqS.GetNoTxn(c).Delete(t, ""), Should BeNil)
376 So(tqS.GetNoTxn(c).Purge(""), ShouldBeNi l) 376 So(tqS.GetNoTxn(c).Purge(""), ShouldBeNi l)
377 _, err := tqS.GetNoTxn(c).Stats("") 377 _, err := tqS.GetNoTxn(c).Stats("")
378 So(err, ShouldBeNil) 378 So(err, ShouldBeNil)
379 return nil 379 return nil
380 }, nil), ShouldBeNil) 380 }, nil), ShouldBeNil)
381 }) 381 })
382 382
383 Convey("adding a new task only happens if we don't errou t", func() { 383 Convey("adding a new task only happens if we don't errou t", func() {
384 So(dsS.Get(c).RunInTransaction(func(c context.Co ntext) error { 384 So(dsS.Get(c).RunInTransaction(func(c context.Co ntext) error {
385 » » » » » t3 := tq.NewTask("/sandwitch/victory") 385 » » » » » t3 := &tqS.Task{Path: "/sandwitch/victor y"}
386 So(tqS.Get(c).Add(t3, ""), ShouldBeNil) 386 So(tqS.Get(c).Add(t3, ""), ShouldBeNil)
387 return fmt.Errorf("nooooo") 387 return fmt.Errorf("nooooo")
388 }, nil), ShouldErrLike, "nooooo") 388 }, nil), ShouldErrLike, "nooooo")
389 389
390 So(tqt.GetScheduledTasks()["default"][t.Name], S houldResemble, t) 390 So(tqt.GetScheduledTasks()["default"][t.Name], S houldResemble, t)
391 So(tqt.GetTombstonedTasks()["default"][t2.Name], ShouldResemble, t2) 391 So(tqt.GetTombstonedTasks()["default"][t2.Name], ShouldResemble, t2)
392 So(tqt.GetTransactionTasks()["default"], ShouldB eNil) 392 So(tqt.GetTransactionTasks()["default"], ShouldB eNil)
393 }) 393 })
394 394
395 Convey("likewise, a panic doesn't schedule anything", fu nc() { 395 Convey("likewise, a panic doesn't schedule anything", fu nc() {
396 func() { 396 func() {
397 defer func() { _ = recover() }() 397 defer func() { _ = recover() }()
398 So(dsS.Get(c).RunInTransaction(func(c co ntext.Context) error { 398 So(dsS.Get(c).RunInTransaction(func(c co ntext.Context) error {
399 tq := tqS.Get(c) 399 tq := tqS.Get(c)
400 400
401 » » » » » » So(tq.Add(tq.NewTask("/sandwitch /victory"), ""), ShouldBeNil) 401 » » » » » » So(tq.Add(&tqS.Task{Path: "/sand witch/victory"}, ""), ShouldBeNil)
402 402
403 panic(fmt.Errorf("nooooo")) 403 panic(fmt.Errorf("nooooo"))
404 }, nil), ShouldBeNil) 404 }, nil), ShouldBeNil)
405 }() 405 }()
406 406
407 So(tqt.GetScheduledTasks()["default"][t.Name], S houldResemble, t) 407 So(tqt.GetScheduledTasks()["default"][t.Name], S houldResemble, t)
408 So(tqt.GetTombstonedTasks()["default"][t2.Name], ShouldResemble, t2) 408 So(tqt.GetTombstonedTasks()["default"][t2.Name], ShouldResemble, t2)
409 So(tqt.GetTransactionTasks()["default"], ShouldB eNil) 409 So(tqt.GetTransactionTasks()["default"], ShouldB eNil)
410 }) 410 })
411 411
412 }) 412 })
413 }) 413 })
414 } 414 }
OLDNEW
« no previous file with comments | « no previous file | service/taskqueue/interface.go » ('j') | service/taskqueue/types.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698