nomad: more worker testing

This commit is contained in:
Armon Dadgar 2015-07-28 17:20:06 -07:00
parent 8e66fdfdab
commit 3938231a9e
1 changed files with 57 additions and 0 deletions

View File

@ -7,9 +7,38 @@ import (
"time"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/scheduler"
"github.com/hashicorp/nomad/testutil"
)
type NoopScheduler struct {
state scheduler.State
planner scheduler.Planner
eval *structs.Evaluation
err error
}
func (n *NoopScheduler) Process(eval *structs.Evaluation) error {
if n.state == nil {
panic("missing state")
}
if n.planner == nil {
panic("missing planner")
}
n.eval = eval
return n.err
}
func init() {
scheduler.BuiltinSchedulers["noop"] = func(s scheduler.State, p scheduler.Planner) scheduler.Scheduler {
n := &NoopScheduler{
state: s,
planner: p,
}
return n
}
}
func TestWorker_dequeueEvaluation(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0
@ -141,3 +170,31 @@ func TestWorker_waitForIndex(t *testing.T) {
t.Fatalf("err: %v", err)
}
}
func TestWorker_invokeScheduler(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0
c.EnabledSchedulers = []string{structs.JobTypeService}
})
defer s1.Shutdown()
w := &Worker{srv: s1, logger: s1.logger}
eval := mockEval()
eval.Type = "noop"
err := w.invokeScheduler(eval)
if err != nil {
t.Fatalf("err: %v", err)
}
}
func TestWorker_SubmitPlan(t *testing.T) {
s1 := testServer(t, func(c *Config) {
c.NumSchedulers = 0
c.EnabledSchedulers = []string{structs.JobTypeService}
})
defer s1.Shutdown()
testutil.WaitForLeader(t, s1.RPC)
// TODO: This requires the plan apply to work
}