From aa3512d11c93d3e175e2de960d5fcb2cfe24d1bc Mon Sep 17 00:00:00 2001 From: Alex Munda Date: Thu, 1 Jul 2021 08:48:57 -0500 Subject: [PATCH] Update tests after moving idempotency token to WriteOptions --- nomad/job_endpoint_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index 7db2af5e0..5171f9dd9 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -6133,9 +6133,6 @@ func TestJobEndpoint_Dispatch(t *testing.T) { reqInputDataTooLarge := &structs.JobDispatchRequest{ Payload: make([]byte, DispatchPayloadSizeLimit+100), } - reqIdempotentToken := &structs.JobDispatchRequest{ - IdempotencyToken: "foo", - } type existingIdempotentChildJob struct { isTerminal bool @@ -6148,6 +6145,7 @@ func TestJobEndpoint_Dispatch(t *testing.T) { noEval bool err bool errStr string + idempotencyToken string existingIdempotentJob *existingIdempotentChildJob } cases := []testCase{ @@ -6244,16 +6242,18 @@ func TestJobEndpoint_Dispatch(t *testing.T) { { name: "idempotency token, no existing child job", parameterizedJob: d1, - dispatchReq: reqIdempotentToken, + dispatchReq: reqInputDataNoMeta, err: false, + idempotencyToken: "foo", existingIdempotentJob: nil, }, { name: "idempotency token, w/ existing non-terminal child job", parameterizedJob: d1, - dispatchReq: reqIdempotentToken, + dispatchReq: reqInputDataNoMeta, err: true, - errStr: "dispatch violates idempotency token of non-terminal child job", + errStr: "idempotent dispatch failed: another child job with this token is running or pending", + idempotencyToken: "foo", existingIdempotentJob: &existingIdempotentChildJob{ isTerminal: false, }, @@ -6261,8 +6261,9 @@ func TestJobEndpoint_Dispatch(t *testing.T) { { name: "idempotency token, w/ existing terminal job", parameterizedJob: d1, - dispatchReq: reqIdempotentToken, + dispatchReq: reqInputDataNoMeta, err: false, + idempotencyToken: "foo", existingIdempotentJob: &existingIdempotentChildJob{ isTerminal: true, }, @@ -6296,8 +6297,9 @@ func TestJobEndpoint_Dispatch(t *testing.T) { // Now try to dispatch tc.dispatchReq.JobID = tc.parameterizedJob.ID tc.dispatchReq.WriteRequest = structs.WriteRequest{ - Region: "global", - Namespace: tc.parameterizedJob.Namespace, + Region: "global", + Namespace: tc.parameterizedJob.Namespace, + IdempotencyToken: tc.idempotencyToken, } // Dispatch with the same request so a child job w/ the idempotency key exists