X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fd3e91e6cd737554b4ae491a558e52f41bad3d07..4557160adb2a68c3462fb339f49900d14a271112:/services/crunch-dispatch-local/crunch-dispatch-local_test.go diff --git a/services/crunch-dispatch-local/crunch-dispatch-local_test.go b/services/crunch-dispatch-local/crunch-dispatch-local_test.go index bcb406eb8e..1a2787c25c 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local_test.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local_test.go @@ -1,12 +1,12 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( "bytes" - "git.curoverse.com/arvados.git/sdk/go/arvados" - "git.curoverse.com/arvados.git/sdk/go/arvadosclient" - "git.curoverse.com/arvados.git/sdk/go/arvadostest" - "git.curoverse.com/arvados.git/sdk/go/dispatch" - . "gopkg.in/check.v1" + "context" "io" "log" "net/http" @@ -16,6 +16,12 @@ import ( "strings" "testing" "time" + + "git.curoverse.com/arvados.git/sdk/go/arvados" + "git.curoverse.com/arvados.git/sdk/go/arvadosclient" + "git.curoverse.com/arvados.git/sdk/go/arvadostest" + "git.curoverse.com/arvados.git/sdk/go/dispatch" + . "gopkg.in/check.v1" ) // Gocheck boilerplate @@ -62,17 +68,15 @@ func (s *TestSuite) TestIntegration(c *C) { echo := "echo" crunchRunCommand = &echo - doneProcessing := make(chan struct{}) + ctx, cancel := context.WithCancel(context.Background()) dispatcher := dispatch.Dispatcher{ - Arv: arv, - PollInterval: time.Second, - RunContainer: func(dispatcher *dispatch.Dispatcher, - container arvados.Container, - status chan arvados.Container) { - run(dispatcher, container, status) - doneProcessing <- struct{}{} + Arv: arv, + PollPeriod: time.Second, + RunContainer: func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { + run(d, c, s) + cancel() }, - DoneProcessing: doneProcessing} + } startCmd = func(container arvados.Container, cmd *exec.Cmd) error { dispatcher.UpdateState(container.UUID, "Running") @@ -80,8 +84,8 @@ func (s *TestSuite) TestIntegration(c *C) { return cmd.Start() } - err = dispatcher.RunDispatcher() - c.Assert(err, IsNil) + err = dispatcher.Run(ctx) + c.Assert(err, Equals, context.Canceled) // Wait for all running crunch jobs to complete / terminate waitGroup.Wait() @@ -116,7 +120,7 @@ func (s *MockArvadosServerSuite) Test_APIErrorUpdatingContainerState(c *C) { apiStubResponses["/arvados/v1/containers/zzzzz-dz642-xxxxxxxxxxxxxx1"] = arvadostest.StubResponse{500, string(`{}`)} - testWithServerStub(c, apiStubResponses, "echo", "Error locking container zzzzz-dz642-xxxxxxxxxxxxxx1") + testWithServerStub(c, apiStubResponses, "echo", "error locking container zzzzz-dz642-xxxxxxxxxxxxxx1") } func (s *MockArvadosServerSuite) Test_ContainerStillInRunningAfterRun(c *C) { @@ -166,17 +170,15 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon *crunchRunCommand = crunchCmd - doneProcessing := make(chan struct{}) + ctx, cancel := context.WithCancel(context.Background()) dispatcher := dispatch.Dispatcher{ - Arv: arv, - PollInterval: time.Duration(1) * time.Second, - RunContainer: func(dispatcher *dispatch.Dispatcher, - container arvados.Container, - status chan arvados.Container) { - run(dispatcher, container, status) - doneProcessing <- struct{}{} + Arv: arv, + PollPeriod: time.Duration(1) * time.Second, + RunContainer: func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { + run(d, c, s) + cancel() }, - DoneProcessing: doneProcessing} + } startCmd = func(container arvados.Container, cmd *exec.Cmd) error { dispatcher.UpdateState(container.UUID, "Running") @@ -188,11 +190,11 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon for i := 0; i < 80 && !strings.Contains(buf.String(), expected); i++ { time.Sleep(100 * time.Millisecond) } - dispatcher.DoneProcessing <- struct{}{} + cancel() }() - err := dispatcher.RunDispatcher() - c.Assert(err, IsNil) + err := dispatcher.Run(ctx) + c.Assert(err, Equals, context.Canceled) // Wait for all running crunch jobs to complete / terminate waitGroup.Wait()