2015-07-27 22:31:49 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2015-08-12 22:44:36 +00:00
|
|
|
"time"
|
2015-07-27 22:31:49 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/net-rpc-msgpackrpc"
|
2015-08-11 21:27:14 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
2015-07-27 22:31:49 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPlanEndpoint_Submit(t *testing.T) {
|
2017-07-23 22:04:38 +00:00
|
|
|
t.Parallel()
|
2015-08-12 22:44:36 +00:00
|
|
|
s1 := testServer(t, func(c *Config) {
|
|
|
|
c.NumSchedulers = 0
|
|
|
|
})
|
2015-07-27 22:31:49 +00:00
|
|
|
defer s1.Shutdown()
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
|
|
|
|
2015-08-12 22:44:36 +00:00
|
|
|
// Create the register request
|
|
|
|
eval1 := mock.Eval()
|
2016-05-18 18:35:15 +00:00
|
|
|
s1.evalBroker.Enqueue(eval1)
|
|
|
|
|
2015-08-12 22:44:36 +00:00
|
|
|
evalOut, token, err := s1.evalBroker.Dequeue([]string{eval1.Type}, time.Second)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if evalOut != eval1 {
|
|
|
|
t.Fatalf("Bad eval")
|
|
|
|
}
|
|
|
|
|
2015-07-27 22:31:49 +00:00
|
|
|
// Submit a plan
|
2015-08-11 21:27:14 +00:00
|
|
|
plan := mock.Plan()
|
2015-08-12 22:44:36 +00:00
|
|
|
plan.EvalID = eval1.ID
|
|
|
|
plan.EvalToken = token
|
2017-10-13 21:36:02 +00:00
|
|
|
plan.Job = mock.Job()
|
2015-07-27 22:31:49 +00:00
|
|
|
req := &structs.PlanRequest{
|
|
|
|
Plan: plan,
|
2015-09-14 01:18:40 +00:00
|
|
|
WriteRequest: structs.WriteRequest{Region: "global"},
|
2015-07-27 22:31:49 +00:00
|
|
|
}
|
|
|
|
var resp structs.PlanResponse
|
|
|
|
if err := msgpackrpc.CallWithCodec(codec, "Plan.Submit", req, &resp); err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if resp.Result == nil {
|
|
|
|
t.Fatalf("missing result")
|
|
|
|
}
|
|
|
|
}
|