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

Unified Diff: appengine/tsmon/handler_test.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/tsmon/handler.go ('k') | appengine/tsmon/middleware.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/tsmon/handler_test.go
diff --git a/appengine/tsmon/handler_test.go b/appengine/tsmon/handler_test.go
index 2a91ec25fdc69f6424569ba3d4f26d2d52ebf418..d4132c6c2526f902ce9f036b008401adaa2d6d0a 100644
--- a/appengine/tsmon/handler_test.go
+++ b/appengine/tsmon/handler_test.go
@@ -11,20 +11,21 @@ import (
"testing"
"time"
"github.com/luci/gae/service/datastore"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/appengine/gaetesting"
"github.com/luci/luci-go/common/clock/testclock"
"github.com/luci/luci-go/common/logging/gologger"
"github.com/luci/luci-go/common/tsmon"
"github.com/luci/luci-go/common/tsmon/monitor"
+ "github.com/luci/luci-go/server/router"
"golang.org/x/net/context"
. "github.com/smartystreets/goconvey/convey"
)
type fakeInfo struct {
info.RawInterface
}
func (i *fakeInfo) InstanceID() string { return "instance" }
@@ -91,42 +92,50 @@ func buildTestState() (*State, *monitor.Fake) {
func TestHousekeepingHandler(t *testing.T) {
Convey("Assigns task numbers to unassigned instances", t, func() {
c, _ := buildGAETestContext()
i, err := getOrCreateInstanceEntity(c)
So(err, ShouldBeNil)
So(i.TaskNum, ShouldEqual, -1)
rec := httptest.NewRecorder()
- housekeepingHandler(c, rec, &http.Request{}, nil)
+ housekeepingHandler(&router.Context{
+ Context: c,
+ Writer: rec,
+ Request: &http.Request{},
+ })
So(rec.Code, ShouldEqual, http.StatusOK)
i, err = getOrCreateInstanceEntity(c)
So(err, ShouldBeNil)
So(i.TaskNum, ShouldEqual, 0)
})
Convey("Doesn't reassign the same task number", t, func() {
c, clock := buildGAETestContext()
otherInstance := instance{
ID: "foobar",
TaskNum: 0,
LastUpdated: clock.Now(),
}
So(datastore.Get(c).Put(&otherInstance), ShouldBeNil)
getOrCreateInstanceEntity(c)
rec := httptest.NewRecorder()
- housekeepingHandler(c, rec, &http.Request{}, nil)
+ housekeepingHandler(&router.Context{
+ Context: c,
+ Writer: rec,
+ Request: &http.Request{},
+ })
So(rec.Code, ShouldEqual, http.StatusOK)
i, err := getOrCreateInstanceEntity(c)
So(err, ShouldBeNil)
So(i.TaskNum, ShouldEqual, 1)
})
Convey("Expires old instances", t, func() {
c, clock := buildGAETestContext()
ds := datastore.Get(c)
@@ -137,18 +146,22 @@ func TestHousekeepingHandler(t *testing.T) {
LastUpdated: clock.Now(),
}
So(ds.Put(&oldInstance), ShouldBeNil)
exists, err := ds.Exists(ds.NewKey("Instance", "foobar", 0, nil))
So(err, ShouldBeNil)
So(exists.All(), ShouldBeTrue)
clock.Add(instanceExpirationTimeout + time.Second)
rec := httptest.NewRecorder()
- housekeepingHandler(c, rec, &http.Request{}, nil)
+ housekeepingHandler(&router.Context{
+ Context: c,
+ Writer: rec,
+ Request: &http.Request{},
+ })
So(rec.Code, ShouldEqual, http.StatusOK)
exists, err = ds.Exists(ds.NewKey("Instance", "foobar", 0, nil))
So(err, ShouldBeNil)
So(exists.All(), ShouldBeFalse)
})
}
« no previous file with comments | « appengine/tsmon/handler.go ('k') | appengine/tsmon/middleware.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698