github.com/taylorchu/nomad@v0.5.3-rc1.0.20170407200202-db11e7dd7b55/nomad/plan_apply_pool_test.go (about) 1 package nomad 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/nomad/mock" 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 func TestEvaluatePool(t *testing.T) { 11 state := testStateStore(t) 12 node := mock.Node() 13 state.UpsertNode(1000, node) 14 snap, _ := state.Snapshot() 15 16 alloc := mock.Alloc() 17 plan := &structs.Plan{ 18 NodeAllocation: map[string][]*structs.Allocation{ 19 node.ID: []*structs.Allocation{alloc}, 20 }, 21 } 22 23 pool := NewEvaluatePool(1, 4) 24 defer pool.Shutdown() 25 26 // Push a request 27 req := pool.RequestCh() 28 req <- evaluateRequest{snap, plan, node.ID} 29 30 // Get the response 31 res := <-pool.ResultCh() 32 33 // Verify response 34 if res.err != nil { 35 t.Fatalf("err: %v", res.err) 36 } 37 if !res.fit { 38 t.Fatalf("bad") 39 } 40 } 41 42 func TestEvaluatePool_Resize(t *testing.T) { 43 pool := NewEvaluatePool(1, 4) 44 defer pool.Shutdown() 45 if n := pool.Size(); n != 1 { 46 t.Fatalf("bad: %d", n) 47 } 48 49 // Scale up 50 pool.SetSize(4) 51 if n := pool.Size(); n != 4 { 52 t.Fatalf("bad: %d", n) 53 } 54 55 // Scale down 56 pool.SetSize(2) 57 if n := pool.Size(); n != 2 { 58 t.Fatalf("bad: %d", n) 59 } 60 }