Skip to content

Commit 955112f

Browse files
Merge pull request #1483 from openshift-cloud-team/fix-flaky-mhc-requeue-test
NO-JIRA: fix flaky TestReconcile/machine_with_node_likely_to_go_unhealthy#1483
2 parents 4566a9a + b60e775 commit 955112f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/controller/machinehealthcheck/machinehealthcheck_controller_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type testCase struct {
5353
expectedStatus *machinev1.MachineHealthCheckStatus
5454
externalRemediationMachine *unstructured.Unstructured
5555
externalRemediationTemplate *unstructured.Unstructured
56+
// setup is called immediately before the reconcile to allow time-sensitive
57+
// test cases to refresh state (e.g. LastTransitionTime) right before execution.
58+
setup func()
5659
}
5760

5861
type expectedReconcile struct {
@@ -325,6 +328,9 @@ func TestReconcile(t *testing.T) {
325328
machine: machineWithNodeRecentlyUnhealthy,
326329
node: nodeRecentlyUnhealthy,
327330
mhc: machineHealthCheck,
331+
setup: func() {
332+
nodeRecentlyUnhealthy.Status.Conditions[0].LastTransitionTime = metav1.Time{Time: time.Now()}
333+
},
328334
expected: expectedReconcile{
329335
result: reconcile.Result{
330336
RequeueAfter: 300 * time.Second,
@@ -488,6 +494,9 @@ func TestReconcile(t *testing.T) {
488494

489495
for _, tc := range testCases {
490496
t.Run(tc.name, func(t *testing.T) {
497+
if tc.setup != nil {
498+
tc.setup()
499+
}
491500
recorder := record.NewFakeRecorder(2)
492501
r := newFakeReconcilerWithCustomRecorder(recorder, buildRunTimeObjects(tc)...)
493502
assertBaseReconcile(t, tc, ctx, r)

0 commit comments

Comments
 (0)