| 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)
|
| })
|
| }
|
|
|