Skip to content

Commit

Permalink
Fix race in WebConsoleRequest controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyar85 committed Dec 16, 2024
1 parent 32a7325 commit 00731ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 00731ec

Please sign in to comment.