8128: Fix test race.
authorTom Clegg <tom@curoverse.com>
Thu, 12 May 2016 14:23:31 +0000 (10:23 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 12 May 2016 15:33:45 +0000 (11:33 -0400)
services/crunch-dispatch-local/crunch-dispatch-local.go

index 848d723380da29d9a9e3337aa654e097fde782e1..40238706063c6659f0e39d89ac1af7eca5e85795 100644 (file)
@@ -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{})