From 79ed8ab99bb2ad779c873620704519cf02177962 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Wed, 13 Apr 2022 14:27:52 -0400 Subject: [PATCH] 18947: Fix panic in tests when TestIntegration doesn't run first. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- .../crunch-dispatch-local/crunch-dispatch-local.go | 10 +++++----- .../crunch-dispatch-local_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/crunch-dispatch-local/crunch-dispatch-local.go b/services/crunch-dispatch-local/crunch-dispatch-local.go index 968b556a27..c33c2358ca 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local.go @@ -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) } diff --git a/services/crunch-dispatch-local/crunch-dispatch-local_test.go b/services/crunch-dispatch-local/crunch-dispatch-local_test.go index 5d6176b047..e5ce5c66c5 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local_test.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local_test.go @@ -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() -- 2.30.2