Skip to content

Commit 1a15e5a

Browse files
committed
Fix race in VirtualMachineSetResourcePolicy integration test
There is a data race with the called variable. Switch it to an atomic until we revise how we're testing the whole provider interface, and the interface itself.
1 parent a148db0 commit 1a15e5a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

controllers/virtualmachinesetresourcepolicy/virtualmachinesetresourcepolicy_controller_intg_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package virtualmachinesetresourcepolicy_test
55

66
import (
77
"context"
8+
"sync/atomic"
89

910
. "github.com/onsi/ginkgo"
1011
. "github.com/onsi/gomega"
@@ -63,12 +64,14 @@ func intgTests() {
6364
}
6465

6566
Context("Reconcile", func() {
66-
var called bool
67+
var called atomic.Bool
6768

6869
BeforeEach(func() {
70+
called.Store(false)
71+
6972
intgFakeVMProvider.Lock()
7073
intgFakeVMProvider.CreateOrUpdateVirtualMachineSetResourcePolicyFn = func(_ context.Context, _ *vmopv1alpha1.VirtualMachineSetResourcePolicy) error {
71-
called = true
74+
called.Store(true)
7275
return nil
7376
}
7477
intgFakeVMProvider.Unlock()
@@ -82,7 +85,7 @@ func intgTests() {
8285
})
8386

8487
By("Create policy should be called", func() {
85-
Eventually(called).Should(BeTrue())
88+
Eventually(called.Load).Should(BeTrue())
8689
})
8790

8891
By("Deleting the VirtualMachineSetResourcePolicy", func() {

0 commit comments

Comments
 (0)