Repository: hashicorp/nomad
File: scheduler/reconciler/reconcile_cluster_prop_test.go (Go)

Code before:
		// TODO(tgross): this where the properties under test go
	}))

	t.Run("service jobs", rapid.MakeCheck(func(t *rapid.T) {
		ar := genAllocReconciler(structs.JobTypeService, &idGenerator{}).Draw(t, "reconciler")
		results := ar.Compute()

		/*
			SAFETY properties ("something bad never happens")
		*/

		if results == nil {
			t.Fatal("results should never be nil")
		}

		// stopped jobs
		if ar.jobState.Job.Stopped() {
			if ar.jobState.DeploymentCurrent != nil {
				if results.Deployment != nil {
					t.Fatal("stopped jobs with current deployments should never result in a new deployment")
				}
				if results.Stop == nil {
					t.Fatal("stopped jobs with current deployments should always have stopped allocs")
				}
			}
			if results.DesiredTGUpdates == nil {
				t.Fatal("stopped jobs should result in non-nil desired task group updates")
			}
		}

		if ar.jobState.DeploymentFailed && results.Deployment != nil {
			t.Fatal("failed deployments should never result in new deployments")
		}

		if !ar.clusterState.SupportsDisconnectedClients && results.ReconnectUpdates != nil {
			t.Fatal("task groups that don't support disconnected clients should never result in reconnect updates")
		}

		if ar.jobState.DeploymentCurrent == nil && ar.jobState.DeploymentOld == nil && len(ar.jobState.ExistingAllocs) == 0 {
			count := 0
			for _, tg := range ar.jobState.Job.TaskGroups {
				count += tg.Count
			}
			if len(results.Place) > count {
				t.Fatal("for new jobs, amount of allocs to place should never exceed total tg count")
			}
		}

		/*
			LIVENESS properties ("something good eventually happens")
		*/

Review comment (suggestion):
It looks like this property is unconditionally true, as we initialize `DesiredTGUpdates` everywhere, so we can lift it out of the `Stopped` condition.

Code after:
		// TODO(tgross): this where the properties under test go
	}))

	t.Run("service jobs", rapid.MakeCheck(func(t *rapid.T) {
		ar := genAllocReconciler(structs.JobTypeService, &idGenerator{}).Draw(t, "reconciler")
		results := ar.Compute()

		/*
			SAFETY properties ("something bad never happens")
		*/

		if results == nil {
			t.Fatal("results should never be nil")
		}

		// stopped jobs
		if ar.jobState.Job.Stopped() {
			if ar.jobState.DeploymentCurrent != nil {
				if results.Deployment != nil {
					t.Fatal("stopped jobs with current deployments should never result in a new deployment")
				}
				if results.Stop == nil {
					t.Fatal("stopped jobs with current deployments should always have stopped allocs")
				}
			}
		}

		if results.DesiredTGUpdates == nil {
			t.Fatal("we should never have nil desired task group updates")
		}

		if ar.jobState.DeploymentFailed && results.Deployment != nil {
			t.Fatal("failed deployments should never result in new deployments")
		}

		if !ar.clusterState.SupportsDisconnectedClients && results.ReconnectUpdates != nil {
			t.Fatal("task groups that don't support disconnected clients should never result in reconnect updates")
		}

		if ar.jobState.DeploymentCurrent == nil && ar.jobState.DeploymentOld == nil && len(ar.jobState.ExistingAllocs) == 0 {
			count := 0
			for _, tg := range ar.jobState.Job.TaskGroups {
				count += tg.Count
			}
			if len(results.Place) > count {
				t.Fatal("for new jobs, amount of allocs to place should never exceed total tg count")
			}
		}
	}))
}