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

Unified Diff: appengine/tumble/tumbletest.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 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
« no previous file with comments | « appengine/tumble/service.go ('k') | common/prpc/talk/buildbot/frontend/handler.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
« no previous file with comments | « appengine/tumble/service.go ('k') | common/prpc/talk/buildbot/frontend/handler.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698