"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/ctxlog"
"git.arvados.org/arvados.git/sdk/go/dispatch"
- "github.com/sirupsen/logrus"
. "gopkg.in/check.v1"
)
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) {
- arvadostest.StopAPI()
}
func (s *TestSuite) SetUpTest(c *C) {
+ arvadostest.ResetDB(c)
+ arvadostest.ResetEnv()
args := []string{"crunch-dispatch-local"}
os.Args = args
}
func (s *TestSuite) TearDownTest(c *C) {
arvadostest.ResetEnv()
+ arvadostest.ResetDB(c)
os.Args = initialArgs
}
c.Assert(err, IsNil)
echo := "echo"
- crunchRunCommand = &echo
+ crunchRunCommand = echo
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(ctxlog.Context(context.Background(), ctxlog.TestLogger(c)))
dispatcher := dispatch.Dispatcher{
Arv: arv,
PollPeriod: time.Second,
return cmd.Start()
}
- dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) {
- (&LocalRun{startCmd, make(chan bool, 8), ctx}).run(d, c, s)
- cancel()
+ cl := arvados.Cluster{Containers: arvados.ContainersConfig{RuntimeEngine: "docker"}}
+
+ dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) error {
+ defer cancel()
+ return (&LocalRun{startCmd, make(chan bool, 8), ctx, &cl}).run(d, c, s)
}
err = dispatcher.Run(ctx)
}
buf := bytes.NewBuffer(nil)
- logrus.SetOutput(io.MultiWriter(buf, os.Stderr))
- defer logrus.SetOutput(os.Stderr)
+ logger := ctxlog.TestLogger(c)
+ logger.SetOutput(io.MultiWriter(buf, logger.Out))
- *crunchRunCommand = crunchCmd
+ crunchRunCommand = crunchCmd
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(ctxlog.Context(context.Background(), logger))
+ defer cancel()
dispatcher := dispatch.Dispatcher{
+ Logger: logger,
Arv: arv,
- PollPeriod: time.Second / 20,
+ PollPeriod: time.Second,
}
startCmd := func(container arvados.Container, cmd *exec.Cmd) error {
return cmd.Start()
}
- dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) {
- (&LocalRun{startCmd, make(chan bool, 8), ctx}).run(d, c, s)
- cancel()
+ cl := arvados.Cluster{Containers: arvados.ContainersConfig{RuntimeEngine: "docker"}}
+
+ dispatcher.RunContainer = func(d *dispatch.Dispatcher, c arvados.Container, s <-chan arvados.Container) error {
+ defer cancel()
+ return (&LocalRun{startCmd, make(chan bool, 8), ctx, &cl}).run(d, c, s)
}
re := regexp.MustCompile(`(?ms).*` + expected + `.*`)
err := dispatcher.Run(ctx)
c.Assert(err, Equals, context.Canceled)
+ c.Check(buf.String(), Matches, `(?ms).*`+expected+`.*`)
- // Wait for all running crunch jobs to complete / terminate
+ c.Logf("test finished, waiting for running crunch jobs to complete / terminate")
waitGroup.Wait()
-
- c.Check(buf.String(), Matches, `(?ms).*`+expected+`.*`)
}