+// 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"
"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
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")
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()
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) {
*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")
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()