X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/58044098495d066effa7fd4742b6635d9a10fdfb..d2f732034404f96ebd50999313cbe9a6727d3f95:/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 a1a6d5641e..d976bf0812 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local_test.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local_test.go @@ -12,15 +12,15 @@ import ( "net/http/httptest" "os" "os/exec" - "strings" + "regexp" "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" - "github.com/Sirupsen/logrus" + "git.arvados.org/arvados.git/sdk/go/arvados" + "git.arvados.org/arvados.git/sdk/go/arvadosclient" + "git.arvados.org/arvados.git/sdk/go/arvadostest" + "git.arvados.org/arvados.git/sdk/go/dispatch" + "github.com/sirupsen/logrus" . "gopkg.in/check.v1" ) @@ -41,6 +41,7 @@ func (s *TestSuite) SetUpSuite(c *C) { initialArgs = os.Args arvadostest.StartAPI() runningCmds = make(map[string]*exec.Cmd) + logrus.SetFormatter(&logrus.TextFormatter{DisableColors: true}) } func (s *TestSuite) TearDownSuite(c *C) { @@ -72,18 +73,21 @@ func (s *TestSuite) TestIntegration(c *C) { dispatcher := dispatch.Dispatcher{ Arv: arv, PollPeriod: time.Second, - RunContainer: func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { - run(d, c, s) - cancel() - }, } - startCmd = func(container arvados.Container, cmd *exec.Cmd) error { + startCmd := func(container arvados.Container, cmd *exec.Cmd) error { dispatcher.UpdateState(container.UUID, "Running") dispatcher.UpdateState(container.UUID, "Complete") return cmd.Start() } + cl := arvados.Cluster{Containers: arvados.ContainersConfig{RuntimeEngine: "docker"}} + + dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { + (&LocalRun{startCmd, make(chan bool, 8), ctx, &cl}).run(d, c, s) + cancel() + } + err = dispatcher.Run(ctx) c.Assert(err, Equals, context.Canceled) @@ -110,7 +114,7 @@ func (s *MockArvadosServerSuite) Test_APIErrorGettingContainers(c *C) { apiStubResponses := make(map[string]arvadostest.StubResponse) apiStubResponses["/arvados/v1/containers"] = arvadostest.StubResponse{500, string(`{}`)} - testWithServerStub(c, apiStubResponses, "echo", "error getting list of containers") + testWithServerStub(c, apiStubResponses, "echo", "error getting count of containers") } func (s *MockArvadosServerSuite) Test_APIErrorUpdatingContainerState(c *C) { @@ -133,7 +137,7 @@ func (s *MockArvadosServerSuite) Test_ContainerStillInRunningAfterRun(c *C) { arvadostest.StubResponse{200, string(`{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx2", "state":"Running", "priority":1, "locked_by_uuid": "` + arvadostest.Dispatch1AuthUUID + `"}`)} testWithServerStub(c, apiStubResponses, "echo", - `after "echo" process termination, container state for zzzzz-dz642-xxxxxxxxxxxxxx2 is "Running"; updating it to "Cancelled"`) + `after \\"echo\\" process termination, container state for zzzzz-dz642-xxxxxxxxxxxxxx2 is \\"Running\\"; updating it to \\"Cancelled\\"`) } func (s *MockArvadosServerSuite) Test_ErrorRunningContainer(c *C) { @@ -144,7 +148,7 @@ func (s *MockArvadosServerSuite) Test_ErrorRunningContainer(c *C) { apiStubResponses["/arvados/v1/containers/zzzzz-dz642-xxxxxxxxxxxxxx3/lock"] = arvadostest.StubResponse{200, string(`{"uuid":"zzzzz-dz642-xxxxxxxxxxxxxx3", "state":"Locked", "priority":1}`)} - testWithServerStub(c, apiStubResponses, "nosuchcommand", `error starting "nosuchcommand" for zzzzz-dz642-xxxxxxxxxxxxxx3`) + testWithServerStub(c, apiStubResponses, "nosuchcommand", `error starting \\"nosuchcommand\\" for zzzzz-dz642-xxxxxxxxxxxxxx3`) } func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubResponse, crunchCmd string, expected string) { @@ -174,20 +178,24 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon dispatcher := dispatch.Dispatcher{ Arv: arv, PollPeriod: time.Second / 20, - RunContainer: func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { - run(d, c, s) - cancel() - }, } - startCmd = func(container arvados.Container, cmd *exec.Cmd) error { + startCmd := func(container arvados.Container, cmd *exec.Cmd) error { dispatcher.UpdateState(container.UUID, "Running") dispatcher.UpdateState(container.UUID, "Complete") return cmd.Start() } + cl := arvados.Cluster{Containers: arvados.ContainersConfig{RuntimeEngine: "docker"}} + + dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) { + (&LocalRun{startCmd, make(chan bool, 8), ctx, &cl}).run(d, c, s) + cancel() + } + + re := regexp.MustCompile(`(?ms).*` + expected + `.*`) go func() { - for i := 0; i < 80 && !strings.Contains(buf.String(), expected); i++ { + for i := 0; i < 80 && !re.MatchString(buf.String()); i++ { time.Sleep(100 * time.Millisecond) } cancel()