X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c1b959750a78509a2f5182dbd17685d010826b64..cd68182c48ec70804a2acbf95331ec25629a9e28:/lib/dispatchcloud/worker/pool_test.go diff --git a/lib/dispatchcloud/worker/pool_test.go b/lib/dispatchcloud/worker/pool_test.go index 7ab4e1b6c2..3867e2c63e 100644 --- a/lib/dispatchcloud/worker/pool_test.go +++ b/lib/dispatchcloud/worker/pool_test.go @@ -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) { @@ -58,20 +68,18 @@ func (suite *PoolSuite) TestCreateUnallocShutdown(c *check.C) { pool.Create(type2) c.Check(pool.Unallocated()[type1], check.Equals, 1) c.Check(pool.Unallocated()[type2], check.Equals, 2) - // Unblock the pending Create calls and (before calling Sync!) - // wait for the pool to process the returned instances. + + // Unblock the pending Create calls. go lameInstanceSet.Release(3) + + // Wait for each instance to either return from its Create + // call, or show up in a poll. suite.wait(c, pool, notify, func() bool { - list, err := lameInstanceSet.Instances(nil) - return err == nil && len(list) == 3 + pool.mtx.RLock() + defer pool.mtx.RUnlock() + return len(pool.workers) == 3 }) - 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) - c.Check(pool.Shutdown(type2), check.Equals, true) suite.wait(c, pool, notify, func() bool { return pool.Unallocated()[type1] == 1 && pool.Unallocated()[type2] == 1 @@ -123,3 +131,5 @@ func (*stubExecutor) SetTarget(cloud.ExecutorTarget) {} func (*stubExecutor) Execute(cmd string, stdin io.Reader) ([]byte, []byte, error) { return nil, nil, nil } + +func (*stubExecutor) Close() {}