// Tests the reconciler handles canary promotion when the canary count equals
// the total correctly
Tests the reconciler handles canary promotion when the canary count equals
the total correctly
// Tests the reconciler handles canary promotion when the canary count equals // the total correctly
func TestReconciler_PromoteCanaries_CanariesEqualCount(t *testing.T) {
	job := mock.Job()
	job.TaskGroups[0].Update = canaryUpdate
	job.TaskGroups[0].Count = 2
	d := structs.NewDeployment(job)
	s := &structs.DeploymentState{
		Promoted:        true,
		DesiredTotal:    2,
		DesiredCanaries: 2,
		PlacedAllocs:    2,
	}
	d.TaskGroups[job.TaskGroups[0].Name] = s
	var allocs []*structs.Allocation
	for i := 0; i < 2; i++ {
		alloc := mock.Alloc()
		alloc.Job = job
		alloc.JobID = job.ID
		alloc.NodeID = structs.GenerateUUID()
		alloc.Name = structs.AllocName(job.ID, job.TaskGroups[0].Name, uint(i))
		alloc.TaskGroup = job.TaskGroups[0].Name
		allocs = append(allocs, alloc)
	}
	handled := make(map[string]allocUpdateType)
	for i := 0; i < 2; i++ {
		canary := mock.Alloc()
		canary.Job = job
		canary.JobID = job.ID
		canary.NodeID = structs.GenerateUUID()
		canary.Name = structs.AllocName(job.ID, job.TaskGroups[0].Name, uint(i))
		canary.TaskGroup = job.TaskGroups[0].Name
		s.PlacedCanaries = append(s.PlacedCanaries, canary.ID)
		canary.DeploymentID = d.ID
		canary.DeploymentStatus = &structs.AllocDeploymentStatus{
			Healthy: helper.BoolToPtr(true),
		}
		allocs = append(allocs, canary)
		handled[canary.ID] = allocUpdateFnIgnore
	}
	mockUpdateFn := allocUpdateFnMock(handled, allocUpdateFnDestructive)
	reconciler := NewAllocReconciler(testLogger(), mockUpdateFn, false, job.ID, job, d, allocs, nil)
	r := reconciler.Compute()
	updates := []*structs.DeploymentStatusUpdate{
		{
			DeploymentID:      d.ID,
			Status:            structs.DeploymentStatusSuccessful,
			StatusDescription: structs.DeploymentStatusDescriptionSuccessful,
		},
	}
	assertResults(t, r, &resultExpectation{
		createDeployment:  nil,
		deploymentUpdates: updates,
		place:             0,
		inplace:           0,
		stop:              2,
		desiredTGUpdates: map[string]*structs.DesiredUpdates{
			job.TaskGroups[0].Name: {
				Stop:   2,
				Ignore: 2,
			},
		},
	})
	assertNoCanariesStopped(t, d, r.stop)
	assertNamesHaveIndexes(t, intRange(0, 1), stopResultsToNames(r.stop))
}
func TestReconciler_PromoteCanaries_CanariesEqualCount ( t * testing . T ) { job := mock . Job ( ) job . TaskGroups [ 0 ] . Update = canaryUpdate job . TaskGroups [ 0 ] . Count = 2 d := structs . NewDeployment ( job ) s := & structs . DeploymentState { Promoted : true , DesiredTotal : 2 , DesiredCanaries : 2 , PlacedAllocs : 2 , } d . TaskGroups [ job . TaskGroups [ 0 ] . Name ] = s var allocs [ ] * structs . Allocation for i := 0 ; i < 2 ; i ++ { alloc := mock . Alloc ( ) alloc . Job = job alloc . JobID = job . ID alloc . NodeID = structs . GenerateUUID ( ) alloc . Name = structs . AllocName ( job . ID , job . TaskGroups [ 0 ] . Name , uint ( i ) ) alloc . TaskGroup = job . TaskGroups [ 0 ] . Name allocs = append ( allocs , alloc ) } handled := make ( map [ string ] allocUpdateType ) for i := 0 ; i < 2 ; i ++ { canary := mock . Alloc ( ) canary . Job = job canary . JobID = job . ID canary . NodeID = structs . GenerateUUID ( ) canary . Name = structs . AllocName ( job . ID , job . TaskGroups [ 0 ] . Name , uint ( i ) ) canary . TaskGroup = job . TaskGroups [ 0 ] . Name s . PlacedCanaries = append ( s . PlacedCanaries , canary . ID ) canary . DeploymentID = d . ID canary . DeploymentStatus = & structs . AllocDeploymentStatus { Healthy : helper . BoolToPtr ( true ) , } allocs = append ( allocs , canary ) handled [ canary . ID ] = allocUpdateFnIgnore } mockUpdateFn := allocUpdateFnMock ( handled , allocUpdateFnDestructive ) reconciler := NewAllocReconciler ( testLogger ( ) , mockUpdateFn , false , job . ID , job , d , allocs , nil ) r := reconciler . Compute ( ) updates := [ ] * structs . DeploymentStatusUpdate { { DeploymentID : d . ID , Status : structs . DeploymentStatusSuccessful , StatusDescription : structs . DeploymentStatusDescriptionSuccessful , } , } assertResults ( t , r , & resultExpectation { createDeployment : nil , deploymentUpdates : updates , place : 0 , inplace : 0 , stop : 2 , desiredTGUpdates : map [ string ] * structs . DesiredUpdates { job . TaskGroups [ 0 ] . Name : { Stop : 2 , Ignore : 2 , } , } , } ) assertNoCanariesStopped ( t , d , r . stop ) assertNamesHaveIndexes ( t , intRange ( 0 , 1 ) , stopResultsToNames ( r . stop ) ) }
Tests the reconciler handles canary promotion when the canary count equals
the total correctly
Tests the reconciler handles canary promotion when the canary count equals the total correctly
// Create an existing deployment that has placed some canaries and mark them // promoted // Create 2 allocations from the old job // Create the canaries // Create one canary // Assert the correct results