From 9dc72fee95946a24e17bd8353d438456d4cc62ad Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sat, 20 Feb 2016 13:25:49 -0800 Subject: [PATCH] nomad: Adding Size to EvaluatePool --- nomad/plan_apply_pool.go | 5 +++++ nomad/plan_apply_pool_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/nomad/plan_apply_pool.go b/nomad/plan_apply_pool.go index a0d69676a..934991ee4 100644 --- a/nomad/plan_apply_pool.go +++ b/nomad/plan_apply_pool.go @@ -53,6 +53,11 @@ func NewEvaluatePool(workers, bufSize int) *EvaluatePool { return p } +// Size returns the current size +func (p *EvaluatePool) Size() int { + return p.workers +} + // SetSize is used to resize the worker pool func (p *EvaluatePool) SetSize(size int) { // Handle an upwards resize diff --git a/nomad/plan_apply_pool_test.go b/nomad/plan_apply_pool_test.go index b592d96c3..3131ef136 100644 --- a/nomad/plan_apply_pool_test.go +++ b/nomad/plan_apply_pool_test.go @@ -42,10 +42,19 @@ func TestEvaluatePool(t *testing.T) { func TestEvaluatePool_Resize(t *testing.T) { pool := NewEvaluatePool(1, 4) defer pool.Shutdown() + if n := pool.Size(); n != 1 { + t.Fatalf("bad: %d", n) + } // Scale up pool.SetSize(4) + if n := pool.Size(); n != 4 { + t.Fatalf("bad: %d", n) + } // Scale down pool.SetSize(2) + if n := pool.Size(); n != 2 { + t.Fatalf("bad: %d", n) + } }