Skip to content

Commit 24a4184

Browse files
authored
Merge pull request #12347 from alimaazamat/race-conditions
🐛 Fix race condition in InMemoryMachine controller tests
2 parents 45f3049 + 746d78f commit 24a4184

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/infrastructure/docker/internal/controllers/backends/inmemory/inmemorymachine_controller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ func TestReconcileNormalEtcd(t *testing.T) {
363363
r.InMemoryManager.AddResourceGroup(klog.KObj(cluster).String())
364364
c := r.InMemoryManager.GetResourceGroup(klog.KObj(cluster).String()).GetClient()
365365

366+
// Note: We have to update the lastTransitionTime of the NodeProvisioned condition
367+
// to ensure provisioning time is not expired yet.
368+
updateNodeProvisionedTime(inMemoryMachineWithNodeProvisioned1)
366369
res, err := r.reconcileNormalETCD(ctx, cluster, cpMachine, inMemoryMachineWithNodeProvisioned1)
367370
g.Expect(err).ToNot(HaveOccurred())
368371
g.Expect(res.IsZero()).To(BeFalse())
@@ -590,6 +593,9 @@ func TestReconcileNormalApiServer(t *testing.T) {
590593
r.InMemoryManager.AddResourceGroup(klog.KObj(cluster).String())
591594
c := r.InMemoryManager.GetResourceGroup(klog.KObj(cluster).String()).GetClient()
592595

596+
// Note: We have to update the lastTransitionTime of the NodeProvisioned condition
597+
// to ensure provisioning time is not expired yet.
598+
updateNodeProvisionedTime(inMemoryMachineWithNodeProvisioned)
593599
res, err := r.reconcileNormalAPIServer(ctx, cluster, cpMachine, inMemoryMachineWithNodeProvisioned)
594600
g.Expect(err).ToNot(HaveOccurred())
595601
g.Expect(res.IsZero()).To(BeFalse())
@@ -821,3 +827,21 @@ func newSelfSignedCACert(key *rsa.PrivateKey) (*x509.Certificate, error) {
821827
c, err := x509.ParseCertificate(b)
822828
return c, errors.WithStack(err)
823829
}
830+
831+
func updateNodeProvisionedTime(machine *infrav1.DevMachine) {
832+
for i := range machine.Status.Conditions {
833+
if machine.Status.Conditions[i].Type == string(infrav1.NodeProvisionedCondition) {
834+
machine.Status.Conditions[i].LastTransitionTime = metav1.Now()
835+
return
836+
}
837+
}
838+
839+
if machine.Status.Deprecated != nil && machine.Status.Deprecated.V1Beta1 != nil {
840+
for i := range machine.Status.Deprecated.V1Beta1.Conditions {
841+
if machine.Status.Deprecated.V1Beta1.Conditions[i].Type == infrav1.NodeProvisionedCondition {
842+
machine.Status.Deprecated.V1Beta1.Conditions[i].LastTransitionTime = metav1.Now()
843+
return
844+
}
845+
}
846+
}
847+
}

0 commit comments

Comments
 (0)