2016-02-20 21:07:09 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2016-02-20 21:07:09 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEvaluatePool(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2016-02-20 21:07:09 +00:00
|
|
|
state := testStateStore(t)
|
|
|
|
node := mock.Node()
|
2020-10-19 13:30:15 +00:00
|
|
|
state.UpsertNode(structs.MsgTypeTestSetup, 1000, node)
|
2016-02-20 21:07:09 +00:00
|
|
|
snap, _ := state.Snapshot()
|
|
|
|
|
|
|
|
alloc := mock.Alloc()
|
|
|
|
plan := &structs.Plan{
|
|
|
|
NodeAllocation: map[string][]*structs.Allocation{
|
2017-09-26 22:26:33 +00:00
|
|
|
node.ID: {alloc},
|
2016-02-20 21:07:09 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2016-02-20 21:23:34 +00:00
|
|
|
|
|
|
|
func TestEvaluatePool_Resize(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2016-02-20 21:23:34 +00:00
|
|
|
pool := NewEvaluatePool(1, 4)
|
|
|
|
defer pool.Shutdown()
|
2016-02-20 21:25:49 +00:00
|
|
|
if n := pool.Size(); n != 1 {
|
|
|
|
t.Fatalf("bad: %d", n)
|
|
|
|
}
|
2016-02-20 21:23:34 +00:00
|
|
|
|
|
|
|
// Scale up
|
|
|
|
pool.SetSize(4)
|
2016-02-20 21:25:49 +00:00
|
|
|
if n := pool.Size(); n != 4 {
|
|
|
|
t.Fatalf("bad: %d", n)
|
|
|
|
}
|
2016-02-20 21:23:34 +00:00
|
|
|
|
|
|
|
// Scale down
|
|
|
|
pool.SetSize(2)
|
2016-02-20 21:25:49 +00:00
|
|
|
if n := pool.Size(); n != 2 {
|
|
|
|
t.Fatalf("bad: %d", n)
|
|
|
|
}
|
2016-02-20 21:23:34 +00:00
|
|
|
}
|