open-nomad/nomad/plan_apply_pool_test.go
Drew Bailey 6c788fdccd
Events/msgtype cleanup (#9117)
* use msgtype in upsert node

adds message type to signature for upsert node, update tests, remove placeholder method

* UpsertAllocs msg type test setup

* use upsertallocs with msg type in signature

update test usage of delete node

delete placeholder msgtype method

* add msgtype to upsert evals signature, update test call sites with test setup msg type

handle snapshot upsert eval outside of FSM and ignore eval event

remove placeholder upsertevalsmsgtype

handle job plan rpc and prevent event creation for plan

msgtype cleanup upsertnodeevents

updatenodedrain msgtype

msg type 0 is a node registration event, so set the default  to the ignore type

* fix named import

* fix signature ordering on upsertnode to match
2020-10-19 09:30:15 -04:00

63 lines
1.1 KiB
Go

package nomad
import (
"testing"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
)
func TestEvaluatePool(t *testing.T) {
t.Parallel()
state := testStateStore(t)
node := mock.Node()
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
snap, _ := state.Snapshot()
alloc := mock.Alloc()
plan := &structs.Plan{
NodeAllocation: map[string][]*structs.Allocation{
node.ID: {alloc},
},
}
pool := NewEvaluatePool(1, 4)
defer pool.Shutdown()
// Push a request
req := pool.RequestCh()
req <- evaluateRequest{snap, plan, node.ID}
// Get the response
res := <-pool.ResultCh()
// Verify response
if res.err != nil {
t.Fatalf("err: %v", res.err)
}
if !res.fit {
t.Fatalf("bad")
}
}
func TestEvaluatePool_Resize(t *testing.T) {
t.Parallel()
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)
}
}