| Index: appengine/tumble/tumbletest.go
|
| diff --git a/appengine/tumble/tumbletest.go b/appengine/tumble/tumbletest.go
|
| index 1eee8acc8fcb71c7a0143446c3902648881d55fc..b102917e8b6b08f538440e8f64cebe880b21c8e0 100644
|
| --- a/appengine/tumble/tumbletest.go
|
| +++ b/appengine/tumble/tumbletest.go
|
| @@ -14,20 +14,21 @@ import (
|
|
|
| "github.com/julienschmidt/httprouter"
|
| "github.com/luci/gae/impl/memory"
|
| "github.com/luci/gae/service/datastore"
|
| "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/cryptorand"
|
| "github.com/luci/luci-go/common/logging"
|
| "github.com/luci/luci-go/common/logging/memlogger"
|
| + "github.com/luci/luci-go/server/router"
|
| "github.com/luci/luci-go/server/settings"
|
| "golang.org/x/net/context"
|
| )
|
|
|
| // Testing is a high-level testing object for testing applications that use
|
| // tumble.
|
| type Testing struct {
|
| Service
|
| }
|
|
|
| @@ -110,43 +111,52 @@ func (t *Testing) Iterate(c context.Context) int {
|
| for _, tsk := range tsks {
|
| logging.Debugf(c, "found task: %v", tsk)
|
| if tsk.ETA.After(clk.Now().UTC()) {
|
| logging.Infof(c, "skipping task: ETA(%s): %s", tsk.ETA, tsk.Path)
|
| continue
|
| }
|
| toks := strings.Split(tsk.Path, "/")
|
|
|
| // Process the shard until a success or hard failure.
|
| retryHTTP(c, func(rec *httptest.ResponseRecorder) {
|
| - t.ProcessShardHandler(c, rec, &http.Request{
|
| - Header: http.Header{"X-AppEngine-QueueName": []string{baseName}},
|
| - }, httprouter.Params{
|
| - {Key: "shard_id", Value: toks[4]},
|
| - {Key: "timestamp", Value: toks[6]},
|
| + t.ProcessShardHandler(&router.Context{
|
| + Context: c,
|
| + Writer: rec,
|
| + Request: &http.Request{
|
| + Header: http.Header{"X-AppEngine-QueueName": []string{baseName}},
|
| + },
|
| + Params: httprouter.Params{
|
| + {Key: "shard_id", Value: toks[4]},
|
| + {Key: "timestamp", Value: toks[6]},
|
| + },
|
| })
|
| })
|
|
|
| if err := tq.Delete(tsk, baseName); err != nil {
|
| panic(fmt.Errorf("Deleting task failed: %s", err))
|
| }
|
| ret++
|
| }
|
| return ret
|
| }
|
|
|
| // FireAllTasks will force all tumble shards to run in the future.
|
| func (t *Testing) FireAllTasks(c context.Context) {
|
| retryHTTP(c, func(rec *httptest.ResponseRecorder) {
|
| // Fire all tasks until a success or hard failure.
|
| - t.FireAllTasksHandler(c, rec, &http.Request{
|
| - Header: http.Header{"X-Appengine-Cron": []string{"true"}},
|
| - }, nil)
|
| + t.FireAllTasksHandler(&router.Context{
|
| + Context: c,
|
| + Writer: rec,
|
| + Request: &http.Request{
|
| + Header: http.Header{"X-Appengine-Cron": []string{"true"}},
|
| + },
|
| + })
|
| })
|
| }
|
|
|
| // AdvanceTime advances the test clock enough so that Iterate will be able to
|
| // pick up tasks in the task queue.
|
| func (t *Testing) AdvanceTime(c context.Context) {
|
| clk := clock.Get(c).(testclock.TestClock)
|
| cfg := t.GetConfig(c)
|
| toAdd := time.Duration(cfg.TemporalMinDelay) + time.Duration(cfg.TemporalRoundFactor) + time.Second
|
| logging.Infof(c, "adding %s to %s", toAdd, clk.Now().UTC())
|
|
|