14360: Note race in docs, fix flaky test.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 6 Nov 2018 22:01:06 +0000 (17:01 -0500)
committerTom Clegg <tclegg@veritasgenetics.com>
Tue, 6 Nov 2018 22:01:06 +0000 (17:01 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/dispatchcloud/worker/pool.go
lib/dispatchcloud/worker/pool_test.go

index 4e331256f9123d37f0c81bda8edaaa096fc82969..45e9da37adc7b544b8eb4e3e001f4554bbd3e3a9 100644 (file)
@@ -185,6 +185,11 @@ func (wp *Pool) Unsubscribe(ch <-chan struct{}) {
 
 // Unallocated returns the number of unallocated (creating + booting +
 // idle + unknown) workers for each instance type.
+//
+// The returned counts should be interpreted as upper bounds, rather
+// than exact counts: they are sometimes artificially high when a
+// newly created instance appears in the driver's Instances() list
+// before the Create() call returns.
 func (wp *Pool) Unallocated() map[arvados.InstanceType]int {
        wp.setupOnce.Do(wp.setup)
        wp.mtx.RLock()
index 790ee851ea693faf98aebb5c6ff62c55b8adec09..f8667e06cdb3917fcbdee4d563833367eb599545 100644 (file)
@@ -19,6 +19,16 @@ const GiB arvados.ByteSize = 1 << 30
 
 var _ = check.Suite(&PoolSuite{})
 
+type lessChecker struct {
+       *check.CheckerInfo
+}
+
+func (*lessChecker) Check(params []interface{}, names []string) (result bool, error string) {
+       return params[0].(int) < params[1].(int), ""
+}
+
+var less = &lessChecker{&check.CheckerInfo{Name: "less", Params: []string{"obtained", "expected"}}}
+
 type PoolSuite struct{}
 
 func (suite *PoolSuite) SetUpSuite(c *check.C) {
@@ -69,8 +79,13 @@ func (suite *PoolSuite) TestCreateUnallocShutdown(c *check.C) {
        c.Check(pool.Unallocated()[type1], check.Equals, 1)
        c.Check(pool.Unallocated()[type2], check.Equals, 2)
        pool.getInstancesAndSync()
-       c.Check(pool.Unallocated()[type1], check.Equals, 1)
-       c.Check(pool.Unallocated()[type2], check.Equals, 2)
+       // Returned counts can be temporarily higher than 1 and 2 if
+       // poll ran before Create() returned.
+       c.Check(pool.Unallocated()[type1], check.Not(less), 1)
+       c.Check(pool.Unallocated()[type2], check.Not(less), 2)
+       suite.wait(c, pool, notify, func() bool {
+               return pool.Unallocated()[type1] == 1 && pool.Unallocated()[type2] == 2
+       })
 
        c.Check(pool.Shutdown(type2), check.Equals, true)
        suite.wait(c, pool, notify, func() bool {