8028: Update the stub based test to use waitGroup.Wait() instead of sleep.
authorradhika <radhika@curoverse.com>
Wed, 20 Jan 2016 17:33:16 +0000 (12:33 -0500)
committerradhika <radhika@curoverse.com>
Wed, 20 Jan 2016 17:36:02 +0000 (12:36 -0500)
services/crunch-dispatch-local/crunch-dispatch-local.go
services/crunch-dispatch-local/crunch-dispatch-local_test.go

index 0255831ccdcde0d4c189db430a442259fe2c0008..be1fef86e1928165e161b57c0788e95c922ba541 100644 (file)
@@ -176,19 +176,15 @@ func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
        // A goroutine to terminate the runner if container priority becomes zero
        priorityTicker := time.NewTicker(time.Duration(priorityPollInterval) * time.Second)
        go func() {
-               for {
-                       select {
-                       case <-priorityTicker.C:
-                               var container Container
-                               err := arv.Get("containers", uuid, nil, &container)
-                               if err != nil {
-                                       log.Printf("Error getting container info for %v: %q", uuid, err)
-                               } else {
-                                       if container.Priority == 0 {
-                                               priorityTicker.Stop()
-                                               cmd.Process.Signal(os.Interrupt)
-                                               return
-                                       }
+               for _ = range priorityTicker.C {
+                       var container Container
+                       err := arv.Get("containers", uuid, nil, &container)
+                       if err != nil {
+                               log.Printf("Error getting container info for %v: %q", uuid, err)
+                       } else {
+                               if container.Priority == 0 {
+                                       priorityTicker.Stop()
+                                       cmd.Process.Signal(os.Interrupt)
                                }
                        }
                }
index ef8cb836c9b5727d32d7fd4fdc0ee51d0c5888c6..3ec1e2ec6b41c4759bd6f75e6cddc847254633ab 100644 (file)
@@ -145,14 +145,14 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
        log.SetOutput(tempfile)
 
        go func() {
-               time.Sleep(1 * time.Second)
+               time.Sleep(2 * time.Second)
                sigChan <- syscall.SIGTERM
        }()
 
        runQueuedContainers(1, 1, crunchCmd)
 
-       // Give some time for run goroutine to complete
-       time.Sleep(5 * time.Second)
+       // Wait for all running crunch jobs to complete / terminate
+       waitGroup.Wait()
 
        buf, _ := ioutil.ReadFile(tempfile.Name())
        c.Check(strings.Contains(string(buf), expected), Equals, true)