From 408acd0b02c1d6f246b3723a9344c68c17d836b2 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 12 May 2016 10:23:31 -0400 Subject: [PATCH] 8128: Fix test race. --- .../crunch-dispatch-local/crunch-dispatch-local.go | 14 +++++++------- 1 file 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 848d723380..4023870606 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local.go @@ -131,10 +131,14 @@ func dispatchLocal(pollInterval time.Duration, crunchRunCommand string) { return } - for i := 0; i < len(containers.Items); i++ { - log.Printf("About to run queued container %v", containers.Items[i].UUID) + for _, c := range containers.Items { + log.Printf("About to run queued container %v", c.UUID) // Run the container - go run(containers.Items[i].UUID, crunchRunCommand, pollInterval) + waitGroup.Add(1) + go func(c Container) { + run(c.UUID, crunchRunCommand, pollInterval) + waitGroup.Done() + }(c) } } @@ -187,10 +191,6 @@ func run(uuid string, crunchRunCommand string, pollInterval time.Duration) { log.Printf("Starting container %v", uuid) - // Add this crunch job to waitGroup - waitGroup.Add(1) - defer waitGroup.Done() - updateState(uuid, "Running") cmdExited := make(chan struct{}) -- 2.39.5