Skip to content

Commit

Permalink
Revert "deployment_watcher_test failing AutoPromoteDeploymentJobStanza"
Browse files Browse the repository at this point in the history
This reverts commit 0661f17.
  • Loading branch information
langmartin committed May 21, 2019
1 parent 9eafade commit 41bb0d5
Showing 1 changed file with 0 additions and 111 deletions.
111 changes: 0 additions & 111 deletions nomad/deploymentwatcher/deployments_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ func TestWatcher_PromoteDeployment_UnhealthyCanaries(t *testing.T) {
m.AssertCalled(t, "UpdateDeploymentPromotion", mocker.MatchedBy(matcher))
}

// Test auto_promote. A deployment with all healthy canaries is automatically promoted
func TestWatcher_AutoPromoteDeployment(t *testing.T) {
t.Parallel()
w, m := defaultTestDeploymentWatcher(t)
Expand Down Expand Up @@ -615,116 +614,6 @@ func TestWatcher_AutoPromoteDeployment(t *testing.T) {
require.False(t, b1.DeploymentStatus.Canary)
}

// Test auto_promote. A deployment with all healthy canaries is automatically promoted, when
// configured in the job stanza rather than the task group
func TestWatcher_AutoPromoteDeploymentJobStanza(t *testing.T) {
t.Parallel()
w, m := defaultTestDeploymentWatcher(t)
now := time.Now()

// Create 1 UpdateStrategy, 1 job (1 TaskGroup), 2 canaries, and 1 deployment
upd := structs.DefaultUpdateStrategy.Copy()
upd.AutoPromote = true
upd.MaxParallel = 2
upd.Canary = 2
upd.ProgressDeadline = 5 * time.Second

j := mock.Job()
j.Update = *upd

d := mock.Deployment()
d.JobID = j.ID

alloc := func() *structs.Allocation {
a := mock.Alloc()
a.DeploymentID = d.ID
a.CreateTime = now.UnixNano()
a.ModifyTime = now.UnixNano()
a.DeploymentStatus = &structs.AllocDeploymentStatus{
Canary: true,
}
return a
}

a := alloc()
b := alloc()

d.TaskGroups[a.TaskGroup].PlacedCanaries = []string{a.ID, b.ID}
d.TaskGroups[a.TaskGroup].DesiredCanaries = 2
require.NoError(t, m.state.UpsertJob(m.nextIndex(), j), "UpsertJob")
require.NoError(t, m.state.UpsertDeployment(m.nextIndex(), d), "UpsertDeployment")
require.NoError(t, m.state.UpsertAllocs(m.nextIndex(), []*structs.Allocation{a, b}), "UpsertAllocs")

// =============================================================
// Support method calls
matchConfig0 := &matchDeploymentStatusUpdateConfig{
DeploymentID: d.ID,
Status: structs.DeploymentStatusFailed,
StatusDescription: structs.DeploymentStatusDescriptionProgressDeadline,
Eval: true,
}
matcher0 := matchDeploymentStatusUpdateRequest(matchConfig0)
m.On("UpdateDeploymentStatus", mocker.MatchedBy(matcher0)).Return(nil)

matchConfig1 := &matchDeploymentAllocHealthRequestConfig{
DeploymentID: d.ID,
Healthy: []string{a.ID, b.ID},
Eval: true,
}
matcher1 := matchDeploymentAllocHealthRequest(matchConfig1)
m.On("UpdateDeploymentAllocHealth", mocker.MatchedBy(matcher1)).Return(nil)

matchConfig2 := &matchDeploymentPromoteRequestConfig{
Promotion: &structs.DeploymentPromoteRequest{
DeploymentID: d.ID,
All: true,
},
Eval: true,
}
matcher2 := matchDeploymentPromoteRequest(matchConfig2)
m.On("UpdateDeploymentPromotion", mocker.MatchedBy(matcher2)).Return(nil)
// =============================================================

// Start the deployment
w.SetEnabled(true, m.state)
testutil.WaitForResult(func() (bool, error) { return 1 == len(w.watchers), nil },
func(err error) { require.Equal(t, 1, len(w.watchers), "Should have 1 deployment") })

// Mark the canaries healthy
req := &structs.DeploymentAllocHealthRequest{
DeploymentID: d.ID,
HealthyAllocationIDs: []string{a.ID, b.ID},
}
var resp structs.DeploymentUpdateResponse
err := w.SetAllocHealth(req, &resp)
require.NoError(t, err)

ws := memdb.NewWatchSet()

testutil.WaitForResult(
func() (bool, error) {
ds, _ := m.state.DeploymentsByJobID(ws, j.Namespace, j.ID, true)
d = ds[0]
return 2 == d.TaskGroups["web"].HealthyAllocs, nil
},
func(err error) { require.NoError(t, err) },
)

require.Equal(t, 1, len(w.watchers), "Deployment should still be active")
m.AssertCalled(t, "UpdateDeploymentPromotion", mocker.MatchedBy(matcher2))

require.Equal(t, "running", d.Status)
require.True(t, d.TaskGroups["web"].Promoted)

a1, _ := m.state.AllocByID(ws, a.ID)
require.False(t, a1.DeploymentStatus.Canary)
require.Equal(t, "pending", a1.ClientStatus)
require.Equal(t, "run", a1.DesiredStatus)

b1, _ := m.state.AllocByID(ws, b.ID)
require.False(t, b1.DeploymentStatus.Canary)
}

// Test pausing a deployment that is running
func TestWatcher_PauseDeployment_Pause_Running(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 41bb0d5

Please sign in to comment.