From 3938231a9efe6d861b7199069337f1199b5b611a Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 28 Jul 2015 17:20:06 -0700 Subject: [PATCH] nomad: more worker testing --- nomad/worker_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/nomad/worker_test.go b/nomad/worker_test.go index f6cd27567..3d8ff6f68 100644 --- a/nomad/worker_test.go +++ b/nomad/worker_test.go @@ -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 +}