// Tests the reconciler properly handles a job in stopped states
Tests the reconciler properly handles a job in stopped states
// Tests the reconciler properly handles a job in stopped states
func TestReconciler_JobStopped(t *testing.T) {
	job := mock.Job()
	job.Stop = true
	cases := []struct {
		name             string
		job              *structs.Job
		jobID, taskGroup string
	}{
		{
			name:      "stopped job",
			job:       job,
			jobID:     job.ID,
			taskGroup: job.TaskGroups[0].Name,
		},
		{
			name:      "nil job",
			job:       nil,
			jobID:     "foo",
			taskGroup: "bar",
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			var allocs []*structs.Allocation
			for i := 0; i < 10; i++ {
				alloc := mock.Alloc()
				alloc.Job = c.job
				alloc.JobID = c.jobID
				alloc.NodeID = structs.GenerateUUID()
				alloc.Name = structs.AllocName(c.jobID, c.taskGroup, uint(i))
				alloc.TaskGroup = c.taskGroup
				allocs = append(allocs, alloc)
			}
			reconciler := NewAllocReconciler(testLogger(), allocUpdateFnIgnore, false, c.jobID, c.job, nil, allocs, nil)
			r := reconciler.Compute()
			assertResults(t, r, &resultExpectation{
				createDeployment:  nil,
				deploymentUpdates: nil,
				place:             0,
				inplace:           0,
				stop:              10,
				desiredTGUpdates: map[string]*structs.DesiredUpdates{
					c.taskGroup: {
						Stop: 10,
					},
				},
			})
			assertNamesHaveIndexes(t, intRange(0, 9), stopResultsToNames(r.stop))
		})
	}
}
func TestReconciler_JobStopped ( t * testing . T ) { job := mock . Job ( ) job . Stop = true cases := [ ] struct { name string job * structs . Job jobID , taskGroup string } { { name : " " , job : job , jobID : job . ID , taskGroup : job . TaskGroups [ 0 ] . Name , } , { name : " " , job : nil , jobID : " " , taskGroup : " " , } , } for _ , c := range cases { t . Run ( c . name , func ( t * testing . T ) { var allocs [ ] * structs . Allocation for i := 0 ; i < 10 ; i ++ { alloc := mock . Alloc ( ) alloc . Job = c . job alloc . JobID = c . jobID alloc . NodeID = structs . GenerateUUID ( ) alloc . Name = structs . AllocName ( c . jobID , c . taskGroup , uint ( i ) ) alloc . TaskGroup = c . taskGroup allocs = append ( allocs , alloc ) } reconciler := NewAllocReconciler ( testLogger ( ) , allocUpdateFnIgnore , false , c . jobID , c . job , nil , allocs , nil ) r := reconciler . Compute ( ) assertResults ( t , r , & resultExpectation { createDeployment : nil , deploymentUpdates : nil , place : 0 , inplace : 0 , stop : 10 , desiredTGUpdates : map [ string ] * structs . DesiredUpdates { c . taskGroup : { Stop : 10 , } , } , } ) assertNamesHaveIndexes ( t , intRange ( 0 , 9 ) , stopResultsToNames ( r . stop ) ) } ) } }
Tests the reconciler properly handles a job in stopped states
Tests the reconciler properly handles a job in stopped states
// Create 10 allocations // Assert the correct results