+func (s *TestSuite) integrationTest(c *C,
+ newSqueueCmd func() *exec.Cmd,
+ newScancelCmd func(arvados.Container) *exec.Cmd,
+ newSbatchCmd func(arvados.Container) *exec.Cmd,
+ newScontrolCmd func(arvados.Container) *exec.Cmd,
+ sbatchCmdComps []string,
+ runContainer func(*dispatch.Dispatcher, arvados.Container)) arvados.Container {
+ arvadostest.ResetEnv()
+
+ arv, err := arvadosclient.MakeArvadosClient()
+ c.Assert(err, IsNil)
+
+ var sbatchCmdLine []string
+
+ // Override sbatchCmd
+ defer func(orig func(arvados.Container) *exec.Cmd) {
+ sbatchCmd = orig
+ }(sbatchCmd)
+
+ if newSbatchCmd != nil {
+ sbatchCmd = newSbatchCmd
+ } else {
+ sbatchCmd = func(container arvados.Container) *exec.Cmd {
+ sbatchCmdLine = sbatchFunc(container).Args
+ return exec.Command("sh")
+ }
+ }
+
+ // Override squeueCmd
+ defer func(orig func() *exec.Cmd) {
+ squeueCmd = orig
+ }(squeueCmd)
+ squeueCmd = newSqueueCmd
+
+ // Override scancel
+ defer func(orig func(arvados.Container) *exec.Cmd) {
+ scancelCmd = orig
+ }(scancelCmd)
+ scancelCmd = newScancelCmd
+
+ // Override scontrol
+ defer func(orig func(arvados.Container) *exec.Cmd) {
+ scontrolCmd = orig
+ }(scontrolCmd)
+ scontrolCmd = newScontrolCmd
+
+ // There should be one queued container
+ params := arvadosclient.Dict{
+ "filters": [][]string{{"state", "=", "Queued"}},
+ }
+ var containers arvados.ContainerList
+ err = arv.List("containers", params, &containers)
+ c.Check(err, IsNil)
+ c.Check(len(containers.Items), Equals, 1)
+
+ theConfig.CrunchRunCommand = []string{"echo"}
+
+ ctx, cancel := context.WithCancel(context.Background())
+ doneRun := make(chan struct{})
+
+ dispatcher := dispatch.Dispatcher{
+ Arv: arv,
+ PollPeriod: time.Duration(1) * time.Second,
+ RunContainer: func(disp *dispatch.Dispatcher, ctr arvados.Container, status <-chan arvados.Container) {
+ go func() {
+ runContainer(disp, ctr)
+ doneRun <- struct{}{}
+ }()
+ run(disp, ctr, status)
+ cancel()
+ },
+ }
+
+ sqCheck = &SqueueChecker{Period: 500 * time.Millisecond}
+
+ err = dispatcher.Run(ctx)
+ <-doneRun
+ c.Assert(err, Equals, context.Canceled)
+
+ sqCheck.Stop()
+
+ c.Check(sbatchCmdLine, DeepEquals, sbatchCmdComps)
+
+ // There should be no queued containers now
+ err = arv.List("containers", params, &containers)
+ c.Check(err, IsNil)
+ c.Check(len(containers.Items), Equals, 0)
+
+ // Previously "Queued" container should now be in "Complete" state
+ var container arvados.Container
+ err = arv.Get("containers", "zzzzz-dz642-queuedcontainer", nil, &container)
+ c.Check(err, IsNil)
+ return container
+}
+