diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go index a843614af..856a99b12 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_intg_test.go @@ -97,12 +97,10 @@ func intgTestsReconcile() { }, } - intgFakeVMProvider.Lock() intgFakeVMProvider.GetVirtualMachineWebMKSTicketFn = func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error) { v1a2ProviderCalled = true return v1a2Ticket, nil } - intgFakeVMProvider.Unlock() }) AfterEach(func() { @@ -147,7 +145,11 @@ func intgTestsReconcile() { g.Expect(wcr.Status.Response).ToNot(BeEmpty()) }).Should(Succeed(), "waiting response to be set") + // Lock to prevent race conditions when reading v1a2ProviderCalled, + // as the fake provider might write to it again if CR is reconciled. + intgFakeVMProvider.Lock() Expect(v1a2ProviderCalled).Should(BeTrue()) + intgFakeVMProvider.Unlock() Expect(wcr.Status.ProxyAddr).To(Equal("192.168.0.1")) Expect(wcr.Status.Response).To(Equal(v1a2Ticket)) Expect(wcr.Status.ExpiryTime.Time).To(BeTemporally("~", time.Now(), webconsolerequest.DefaultExpiryTime)) diff --git a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go index 7a75d87aa..04fac8ab3 100644 --- a/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go +++ b/controllers/virtualmachinewebconsolerequest/v1alpha1/webconsolerequest_unit_test.go @@ -137,7 +137,11 @@ func unitTestsReconcile() { err := reconciler.ReconcileNormal(wcrCtx) Expect(err).ToNot(HaveOccurred()) + // Lock to prevent race conditions when reading v1a2ProviderCalled, + // as the fake provider might write to it again if CR is reconciled. + fakeVMProvider.Lock() Expect(v1a2ProviderCalled).Should(BeTrue()) + fakeVMProvider.Unlock() Expect(wcrCtx.WebConsoleRequest.Status.ProxyAddr).To(Equal("dummy-proxy-ip")) Expect(wcrCtx.WebConsoleRequest.Status.Response).To(Equal(v1a2Ticket)) Expect(wcrCtx.WebConsoleRequest.Status.ExpiryTime.Time).To(BeTemporally("~", time.Now(), webconsolerequest.DefaultExpiryTime))