X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3b3c3a0869c2cf528b9e1c45c969bbbd47f6446e..a05465b46a2b91879596d30b5e8051c937dfa8e9:/services/keepstore/pull_worker_integration_test.go diff --git a/services/keepstore/pull_worker_integration_test.go b/services/keepstore/pull_worker_integration_test.go index 34c2f61a37..3855b4ecd3 100644 --- a/services/keepstore/pull_worker_integration_test.go +++ b/services/keepstore/pull_worker_integration_test.go @@ -1,21 +1,23 @@ -package main +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +package keepstore import ( "bytes" + "context" "errors" "io" "io/ioutil" - "os" "strings" - "testing" - "git.curoverse.com/arvados.git/sdk/go/arvadosclient" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" - "git.curoverse.com/arvados.git/sdk/go/keepclient" + "git.arvados.org/arvados.git/sdk/go/arvadostest" + "git.arvados.org/arvados.git/sdk/go/keepclient" + "github.com/prometheus/client_golang/prometheus" + check "gopkg.in/check.v1" ) -var keepClient *keepclient.KeepClient - type PullWorkIntegrationTestData struct { Name string Locator string @@ -23,55 +25,31 @@ type PullWorkIntegrationTestData struct { GetError string } -func SetupPullWorkerIntegrationTest(t *testing.T, testData PullWorkIntegrationTestData, wantData bool) PullRequest { - os.Setenv("ARVADOS_API_HOST_INSECURE", "true") - - // start api and keep servers - arvadostest.StartAPI() +func (s *HandlerSuite) setupPullWorkerIntegrationTest(c *check.C, testData PullWorkIntegrationTestData, wantData bool) PullRequest { arvadostest.StartKeep(2, false) - keepclient.RefreshServiceDiscovery() - - // make arvadosclient - arv, err := arvadosclient.MakeArvadosClient() - if err != nil { - t.Fatalf("Error creating arv: %s", err) - } - - // keep client - keepClient, err = keepclient.MakeKeepClient(arv) - if err != nil { - t.Fatalf("error creating KeepClient: %s", err) - } - keepClient.Want_replicas = 1 - - // discover keep services - var servers []string - for _, host := range keepClient.LocalRoots() { - servers = append(servers, host) - } - + c.Assert(s.handler.setup(context.Background(), s.cluster, "", prometheus.NewRegistry(), testServiceURL), check.IsNil) // Put content if the test needs it if wantData { - locator, _, err := keepClient.PutB([]byte(testData.Content)) + locator, _, err := s.handler.keepClient.PutB([]byte(testData.Content)) if err != nil { - t.Errorf("Error putting test data in setup for %s %s %v", testData.Content, locator, err) + c.Errorf("Error putting test data in setup for %s %s %v", testData.Content, locator, err) } if locator == "" { - t.Errorf("No locator found after putting test data") + c.Errorf("No locator found after putting test data") } } // Create pullRequest for the test pullRequest := PullRequest{ Locator: testData.Locator, - Servers: servers, } return pullRequest } // Do a get on a block that is not existing in any of the keep servers. // Expect "block not found" error. -func TestPullWorkerIntegration_GetNonExistingLocator(t *testing.T) { +func (s *HandlerSuite) TestPullWorkerIntegration_GetNonExistingLocator(c *check.C) { + c.Assert(s.handler.setup(context.Background(), s.cluster, "", prometheus.NewRegistry(), testServiceURL), check.IsNil) testData := PullWorkIntegrationTestData{ Name: "TestPullWorkerIntegration_GetLocator", Locator: "5d41402abc4b2a76b9719d911017c592", @@ -79,16 +57,16 @@ func TestPullWorkerIntegration_GetNonExistingLocator(t *testing.T) { GetError: "Block not found", } - pullRequest := SetupPullWorkerIntegrationTest(t, testData, false) - defer arvadostest.StopAPI() + pullRequest := s.setupPullWorkerIntegrationTest(c, testData, false) defer arvadostest.StopKeep(2) - performPullWorkerIntegrationTest(testData, pullRequest, t) + s.performPullWorkerIntegrationTest(testData, pullRequest, c) } // Do a get on a block that exists on one of the keep servers. // The setup method will create this block before doing the get. -func TestPullWorkerIntegration_GetExistingLocator(t *testing.T) { +func (s *HandlerSuite) TestPullWorkerIntegration_GetExistingLocator(c *check.C) { + c.Assert(s.handler.setup(context.Background(), s.cluster, "", prometheus.NewRegistry(), testServiceURL), check.IsNil) testData := PullWorkIntegrationTestData{ Name: "TestPullWorkerIntegration_GetLocator", Locator: "5d41402abc4b2a76b9719d911017c592", @@ -96,24 +74,22 @@ func TestPullWorkerIntegration_GetExistingLocator(t *testing.T) { GetError: "", } - pullRequest := SetupPullWorkerIntegrationTest(t, testData, true) - defer arvadostest.StopAPI() + pullRequest := s.setupPullWorkerIntegrationTest(c, testData, true) defer arvadostest.StopKeep(2) - performPullWorkerIntegrationTest(testData, pullRequest, t) + s.performPullWorkerIntegrationTest(testData, pullRequest, c) } // Perform the test. // The test directly invokes the "PullItemAndProcess" rather than // putting an item on the pullq so that the errors can be verified. -func performPullWorkerIntegrationTest(testData PullWorkIntegrationTestData, pullRequest PullRequest, t *testing.T) { +func (s *HandlerSuite) performPullWorkerIntegrationTest(testData PullWorkIntegrationTestData, pullRequest PullRequest, c *check.C) { // Override writePulledBlock to mock PutBlock functionality - defer func(orig func(Volume, []byte, string)) { writePulledBlock = orig }(writePulledBlock) - writePulledBlock = func(v Volume, content []byte, locator string) { - if string(content) != testData.Content { - t.Errorf("writePulledBlock invoked with unexpected data. Expected: %s; Found: %s", testData.Content, content) - } + defer func(orig func(*RRVolumeManager, Volume, []byte, string) error) { writePulledBlock = orig }(writePulledBlock) + writePulledBlock = func(_ *RRVolumeManager, _ Volume, content []byte, _ string) error { + c.Check(string(content), check.Equals, testData.Content) + return nil } // Override GetContent to mock keepclient Get functionality @@ -128,15 +104,15 @@ func performPullWorkerIntegrationTest(testData PullWorkIntegrationTestData, pull return rdr, int64(len(testData.Content)), "", nil } - err := PullItemAndProcess(pullRequest, keepClient) + err := s.handler.pullItemAndProcess(pullRequest) if len(testData.GetError) > 0 { if (err == nil) || (!strings.Contains(err.Error(), testData.GetError)) { - t.Errorf("Got error %v, expected %v", err, testData.GetError) + c.Errorf("Got error %v, expected %v", err, testData.GetError) } } else { if err != nil { - t.Errorf("Got error %v, expected nil", err) + c.Errorf("Got error %v, expected nil", err) } } }