X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/682dd5b6cc23a455766a7651e3e841257660b31c..d121e087ad1b4e91f869dbd57534c6d6ce51d19d:/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 762abff533..8c7a1e222d 100644 --- a/services/keepstore/pull_worker_integration_test.go +++ b/services/keepstore/pull_worker_integration_test.go @@ -3,14 +3,16 @@ package main import ( "bytes" "errors" - "git.curoverse.com/arvados.git/sdk/go/arvadosclient" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" - "git.curoverse.com/arvados.git/sdk/go/keepclient" "io" + "io/ioutil" "net/http" "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" ) var keepClient *keepclient.KeepClient @@ -27,7 +29,7 @@ func SetupPullWorkerIntegrationTest(t *testing.T, testData PullWorkIntegrationTe // start api and keep servers arvadostest.StartAPI() - arvadostest.StartKeep() + arvadostest.StartKeep(2, false) // make arvadosclient arv, err := arvadosclient.MakeArvadosClient() @@ -37,9 +39,8 @@ func SetupPullWorkerIntegrationTest(t *testing.T, testData PullWorkIntegrationTe // keep client keepClient = &keepclient.KeepClient{ - Arvados: &arv, + Arvados: arv, Want_replicas: 1, - Using_proxy: true, Client: &http.Client{}, } @@ -82,6 +83,8 @@ func TestPullWorkerIntegration_GetNonExistingLocator(t *testing.T) { } pullRequest := SetupPullWorkerIntegrationTest(t, testData, false) + defer arvadostest.StopAPI() + defer arvadostest.StopKeep(2) performPullWorkerIntegrationTest(testData, pullRequest, t) } @@ -97,6 +100,8 @@ func TestPullWorkerIntegration_GetExistingLocator(t *testing.T) { } pullRequest := SetupPullWorkerIntegrationTest(t, testData, true) + defer arvadostest.StopAPI() + defer arvadostest.StopKeep(2) performPullWorkerIntegrationTest(testData, pullRequest, t) } @@ -106,28 +111,27 @@ func TestPullWorkerIntegration_GetExistingLocator(t *testing.T) { // putting an item on the pullq so that the errors can be verified. func performPullWorkerIntegrationTest(testData PullWorkIntegrationTestData, pullRequest PullRequest, t *testing.T) { - // Override PutContent to mock PutBlock functionality - defer func(orig func([]byte, string)(error)) { PutContent = orig }(PutContent) - PutContent = func(content []byte, locator string) (err error) { + // 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("PutContent invoked with unexpected data. Expected: %s; Found: %s", testData.Content, content) + t.Errorf("writePulledBlock invoked with unexpected data. Expected: %s; Found: %s", testData.Content, content) } - return } // Override GetContent to mock keepclient Get functionality - defer func(orig func(string, *keepclient.KeepClient)(io.ReadCloser, int64, string, error)) { GetContent = orig }(GetContent) - GetContent = func(signedLocator string, keepClient *keepclient.KeepClient) ( - reader io.ReadCloser, contentLength int64, url string, err error) { + defer func(orig func(string, *keepclient.KeepClient) (io.ReadCloser, int64, string, error)) { + GetContent = orig + }(GetContent) + GetContent = func(signedLocator string, keepClient *keepclient.KeepClient) (reader io.ReadCloser, contentLength int64, url string, err error) { if testData.GetError != "" { return nil, 0, "", errors.New(testData.GetError) } - rdr := &ClosingBuffer{bytes.NewBufferString(testData.Content)} + rdr := ioutil.NopCloser(bytes.NewBufferString(testData.Content)) return rdr, int64(len(testData.Content)), "", nil } - keepClient.Arvados.ApiToken = GenerateRandomApiToken() - err := PullItemAndProcess(pullRequest, keepClient.Arvados.ApiToken, keepClient) + err := PullItemAndProcess(pullRequest, keepClient) if len(testData.GetError) > 0 { if (err == nil) || (!strings.Contains(err.Error(), testData.GetError)) {