18947: Fix panic in tests when TestIntegration doesn't run first.
authorTom Clegg <tom@curii.com>
Wed, 13 Apr 2022 18:27:52 +0000 (14:27 -0400)
committerTom Clegg <tom@curii.com>
Wed, 13 Apr 2022 18:27:52 +0000 (14:27 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/crunch-dispatch-local/crunch-dispatch-local.go
services/crunch-dispatch-local/crunch-dispatch-local_test.go

index 968b556a27e720d100abb705e3b704cb2b237299..c33c2358ca3b7612ef92498edbef9a5562d6b9f5 100644 (file)
@@ -31,7 +31,7 @@ var (
        runningCmds      map[string]*exec.Cmd
        runningCmdsMutex sync.Mutex
        waitGroup        sync.WaitGroup
-       crunchRunCommand *string
+       crunchRunCommand string
 )
 
 func main() {
@@ -50,7 +50,7 @@ func main() {
                10,
                "Interval in seconds to poll for queued containers")
 
-       crunchRunCommand = flags.String(
+       flags.StringVar(&crunchRunCommand,
                "crunch-run-command",
                "/usr/bin/crunch-run",
                "Crunch command to run container")
@@ -198,7 +198,7 @@ func (lr *LocalRun) run(dispatcher *dispatch.Dispatcher,
                waitGroup.Add(1)
                defer waitGroup.Done()
 
-               cmd := exec.Command(*crunchRunCommand, "--runtime-engine="+lr.cluster.Containers.RuntimeEngine, uuid)
+               cmd := exec.Command(crunchRunCommand, "--runtime-engine="+lr.cluster.Containers.RuntimeEngine, uuid)
                cmd.Stdin = nil
                cmd.Stderr = os.Stderr
                cmd.Stdout = os.Stderr
@@ -211,7 +211,7 @@ func (lr *LocalRun) run(dispatcher *dispatch.Dispatcher,
                runningCmdsMutex.Lock()
                if err := lr.startCmd(container, cmd); err != nil {
                        runningCmdsMutex.Unlock()
-                       dispatcher.Logger.Warnf("error starting %q for %s: %s", *crunchRunCommand, uuid, err)
+                       dispatcher.Logger.Warnf("error starting %q for %s: %s", crunchRunCommand, uuid, err)
                        dispatcher.UpdateState(uuid, dispatch.Cancelled)
                } else {
                        runningCmds[uuid] = cmd
@@ -261,7 +261,7 @@ Finish:
        }
        if container.State == dispatch.Locked || container.State == dispatch.Running {
                dispatcher.Logger.Warnf("after %q process termination, container state for %v is %q; updating it to %q",
-                       *crunchRunCommand, uuid, container.State, dispatch.Cancelled)
+                       crunchRunCommand, uuid, container.State, dispatch.Cancelled)
                dispatcher.UpdateState(uuid, dispatch.Cancelled)
        }
 
index 5d6176b0473e3fa549a464bd92fd2096849e1877..e5ce5c66c5eb3f1d60ac2ae91edc54d14b68b71d 100644 (file)
@@ -64,7 +64,7 @@ func (s *TestSuite) TestIntegration(c *C) {
        c.Assert(err, IsNil)
 
        echo := "echo"
-       crunchRunCommand = &echo
+       crunchRunCommand = echo
 
        ctx, cancel := context.WithCancel(ctxlog.Context(context.Background(), ctxlog.TestLogger(c)))
        dispatcher := dispatch.Dispatcher{
@@ -169,7 +169,7 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
        logger := ctxlog.TestLogger(c)
        logger.SetOutput(io.MultiWriter(buf, logger.Out))
 
-       *crunchRunCommand = crunchCmd
+       crunchRunCommand = crunchCmd
 
        ctx, cancel := context.WithCancel(ctxlog.Context(context.Background(), logger))
        defer cancel()