From 04feeef1cc1d8dc3e2fa2ef71723a686c5551a7c Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Fri, 3 Nov 2017 16:49:16 -0500 Subject: [PATCH] Adds comment to handleRollbackValidity method and other small test readability fixes. --- nomad/deploymentwatcher/deployment_watcher.go | 15 +++++++++------ .../deploymentwatcher/deployments_watcher_test.go | 4 +--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nomad/deploymentwatcher/deployment_watcher.go b/nomad/deploymentwatcher/deployment_watcher.go index e8eaa9147df..003268916af 100644 --- a/nomad/deploymentwatcher/deployment_watcher.go +++ b/nomad/deploymentwatcher/deployment_watcher.go @@ -184,17 +184,20 @@ func (w *deploymentWatcher) SetAllocHealth( w.setLatestEval(index) return nil } -func (w *deploymentWatcher) handleRollbackValidity(j *structs.Job, desc string) (*structs.Job, string) { + +// handleRollbackValidity checks if the job being rolled back to has the same spec as the existing job +// Returns a modified description and job accordingly. +func (w *deploymentWatcher) handleRollbackValidity(rollbackJob *structs.Job, desc string) (*structs.Job, string) { // Only rollback if job being changed has a different spec. // This prevents an infinite revert cycle when a previously stable version of the job fails to start up during a rollback // If the job we are trying to rollback to is identical to the current job, we stop because the rollback will not succeed. - if w.j.SpecChanged(j) { - desc = structs.DeploymentStatusDescriptionRollback(desc, j.Version) + if w.j.SpecChanged(rollbackJob) { + desc = structs.DeploymentStatusDescriptionRollback(desc, rollbackJob.Version) } else { - desc = structs.DeploymentStatusDescriptionRollbackNoop(desc, j.Version) - j = nil + desc = structs.DeploymentStatusDescriptionRollbackNoop(desc, rollbackJob.Version) + rollbackJob = nil } - return j, desc + return rollbackJob, desc } func (w *deploymentWatcher) PromoteDeployment( diff --git a/nomad/deploymentwatcher/deployments_watcher_test.go b/nomad/deploymentwatcher/deployments_watcher_test.go index fccc14503c9..7ff51625714 100644 --- a/nomad/deploymentwatcher/deployments_watcher_test.go +++ b/nomad/deploymentwatcher/deployments_watcher_test.go @@ -905,9 +905,7 @@ func TestDeploymentWatcher_RollbackFailed(t *testing.T) { // verify that the job version hasn't changed after upsert m.state.JobByID(nil, structs.DefaultNamespace, j.ID) - if j.Version != 0 { - t.Fatalf("Expected job version 0 but got %v", j.Version) - } + assert.Equal(uint64(0), j.Version, "Expected job version 0 but got ", j.Version) } // Test evaluations are batched between watchers