Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Fix race in WebConsoleRequest controller tests #828

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package v1alpha1_test

import (
"context"
"sync/atomic"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -43,7 +44,7 @@ func intgTestsReconcile() {
wcr *vmopv1a1.WebConsoleRequest
vm *vmopv1a1.VirtualMachine
proxySvc *corev1.Service
v1a2ProviderCalled bool
v1a2ProviderCalled atomic.Bool
)

getWebConsoleRequest := func(ctx *builder.IntegrationTestContext, objKey types.NamespacedName) *vmopv1a1.WebConsoleRequest {
Expand Down Expand Up @@ -99,7 +100,7 @@ func intgTestsReconcile() {

intgFakeVMProvider.Lock()
intgFakeVMProvider.GetVirtualMachineWebMKSTicketFn = func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error) {
dilyar85 marked this conversation as resolved.
Show resolved Hide resolved
v1a2ProviderCalled = true
v1a2ProviderCalled.Store(true)
return v1a2Ticket, nil
}
intgFakeVMProvider.Unlock()
Expand All @@ -109,7 +110,7 @@ func intgTestsReconcile() {
ctx.AfterEach()
ctx = nil
intgFakeVMProvider.Reset()
v1a2ProviderCalled = false
v1a2ProviderCalled.Store(false)
})

Context("Reconcile", func() {
Expand Down Expand Up @@ -147,7 +148,7 @@ func intgTestsReconcile() {
g.Expect(wcr.Status.Response).ToNot(BeEmpty())
}).Should(Succeed(), "waiting response to be set")

Expect(v1a2ProviderCalled).Should(BeTrue())
Expect(v1a2ProviderCalled.Load()).Should(BeTrue())
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
@@ -1,10 +1,11 @@
// Copyright (c) 2022 VMware, Inc. All Rights Reserved.
// Copyright (c) 2022-2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha1_test

import (
"context"
"sync/atomic"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -114,7 +115,7 @@ func unitTestsReconcile() {

Context("ReconcileNormal", func() {
var (
v1a2ProviderCalled bool
v1a2ProviderCalled atomic.Bool
)

BeforeEach(func() {
Expand All @@ -123,21 +124,21 @@ func unitTestsReconcile() {

JustBeforeEach(func() {
fakeVMProvider.GetVirtualMachineWebMKSTicketFn = func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error) {
v1a2ProviderCalled = true
v1a2ProviderCalled.Store(true)
return v1a2Ticket, nil
}
})

AfterEach(func() {
fakeVMProvider.Reset()
v1a2ProviderCalled = false
v1a2ProviderCalled.Store(false)
})

It("returns success", func() {
err := reconciler.ReconcileNormal(wcrCtx)
Expect(err).ToNot(HaveOccurred())

Expect(v1a2ProviderCalled).Should(BeTrue())
Expect(v1a2ProviderCalled.Load()).Should(BeTrue())
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
Loading