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