Merge branch 'main' into 21359-rightclick-newproject-bug
[arvados.git] / lib / controller / federation_test.go
index 4c0ffec60c443bb25f2815ca3a7ea88eeaa9a1ae..599686e3e6cc64866793114839f4167605328f86 100644 (file)
@@ -11,6 +11,7 @@ import (
        "fmt"
        "io"
        "io/ioutil"
+       "net"
        "net/http"
        "net/http/httptest"
        "net/url"
@@ -31,6 +32,9 @@ import (
 var _ = check.Suite(&FederationSuite{})
 
 type FederationSuite struct {
+       ctx    context.Context
+       cancel context.CancelFunc
+
        log logrus.FieldLogger
        // testServer and testHandler are the controller being tested,
        // "zhome".
@@ -47,6 +51,7 @@ type FederationSuite struct {
 }
 
 func (s *FederationSuite) SetUpTest(c *check.C) {
+       s.ctx, s.cancel = context.WithCancel(context.Background())
        s.log = ctxlog.TestLogger(c)
 
        s.remoteServer = newServerFromIntegrationTestEnv(c)
@@ -64,15 +69,17 @@ func (s *FederationSuite) SetUpTest(c *check.C) {
        cluster.API.MaxItemsPerResponse = 1000
        cluster.API.MaxRequestAmplification = 4
        cluster.API.RequestTimeout = arvados.Duration(5 * time.Minute)
+       cluster.Collections.BlobSigning = true
        cluster.Collections.BlobSigningKey = arvadostest.BlobSigningKey
        cluster.Collections.BlobSigningTTL = arvados.Duration(time.Hour * 24 * 14)
        arvadostest.SetServiceURL(&cluster.Services.RailsAPI, "http://localhost:1/")
        arvadostest.SetServiceURL(&cluster.Services.Controller, "http://localhost:/")
-       s.testHandler = &Handler{Cluster: cluster}
+       s.testHandler = &Handler{Cluster: cluster, BackgroundContext: ctxlog.Context(s.ctx, s.log)}
        s.testServer = newServerFromIntegrationTestEnv(c)
-       s.testServer.Server.Handler = httpserver.HandlerWithContext(
-               ctxlog.Context(context.Background(), s.log),
-               httpserver.AddRequestIDs(httpserver.LogRequests(s.testHandler)))
+       s.testServer.Server.BaseContext = func(net.Listener) context.Context {
+               return ctxlog.Context(context.Background(), s.log)
+       }
+       s.testServer.Server.Handler = httpserver.AddRequestIDs(httpserver.LogRequests(s.testHandler))
 
        cluster.RemoteClusters = map[string]arvados.RemoteCluster{
                "zzzzz": {
@@ -112,6 +119,7 @@ func (s *FederationSuite) TearDownTest(c *check.C) {
        if s.testServer != nil {
                s.testServer.Close()
        }
+       s.cancel()
 }
 
 func (s *FederationSuite) testRequest(req *http.Request) *httptest.ResponseRecorder {
@@ -699,7 +707,7 @@ func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *c
        s.testHandler.Cluster.API.MaxTokenLifetime = arvados.Duration(time.Hour)
 
        resp := s.testRequest(req).Result()
-       c.Check(resp.StatusCode, check.Equals, http.StatusOK)
+       c.Assert(resp.StatusCode, check.Equals, http.StatusOK)
 
        cr := s.getCRfromMockRequest(c)
 
@@ -718,7 +726,7 @@ func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *c
        var aca arvados.APIClientAuthorization
        c.Check(json.NewDecoder(resp.Body).Decode(&aca), check.IsNil)
        c.Check(aca.ExpiresAt, check.NotNil) // Time.Now()+BlobSigningTTL
-       t, _ := time.Parse(time.RFC3339Nano, aca.ExpiresAt)
+       t := aca.ExpiresAt
        c.Check(t.After(time.Now().Add(s.testHandler.Cluster.API.MaxTokenLifetime.Duration())), check.Equals, true)
        c.Check(t.Before(time.Now().Add(s.testHandler.Cluster.Collections.BlobSigningTTL.Duration())), check.Equals, true)
 }