14938: Fix unreliable test.
authorTom Clegg <tclegg@veritasgenetics.com>
Mon, 11 Mar 2019 04:32:22 +0000 (00:32 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 11 Mar 2019 04:32:22 +0000 (00:32 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/dispatchcloud/test/stub_driver.go
lib/dispatchcloud/worker/pool_test.go

index 5873e492213b86f58eaa98850c5c00c073cd2aee..4df39d0c46ac7dc538e5c7d9949cd884df8768b4 100644 (file)
@@ -371,7 +371,9 @@ func (si stubInstance) SetTags(tags cloud.InstanceTags) error {
 }
 
 func (si stubInstance) Tags() cloud.InstanceTags {
-       return si.tags
+       // Return a copy to ensure a caller can't change our saved
+       // tags just by writing to the returned map.
+       return copyTags(si.tags)
 }
 
 func (si stubInstance) String() string {
index da9e650b8121889511886e9b16dc8eb827fcee14..fc33a7ab235d7a733903903219302a81c8fc44d0 100644 (file)
@@ -105,6 +105,23 @@ func (suite *PoolSuite) TestResumeAfterRestart(c *check.C) {
                        pool.SetIdleBehavior(heldInstanceID, IdleBehaviorHold)
                }
        }
+       // Wait for the tags to save to the cloud provider
+       deadline := time.Now().Add(time.Second)
+       for !func() bool {
+               pool.mtx.RLock()
+               defer pool.mtx.RUnlock()
+               for _, wkr := range pool.workers {
+                       if wkr.instType == type2 {
+                               return wkr.instance.Tags()[tagKeyIdleBehavior] == string(IdleBehaviorHold)
+                       }
+               }
+               return false
+       }() {
+               if time.Now().After(deadline) {
+                       c.Fatal("timeout")
+               }
+               time.Sleep(time.Millisecond * 10)
+       }
        pool.Stop()
 
        c.Log("------- starting new pool, waiting to recover state")