Skip to content

Commit 1bcc485

Browse files
committed
Fix vhost controller test flakes
There was test pollution from tests that set vhost limits. The vhost limits in RMQ HTTP API are implemented as separate API endpoints. When a vhost has a limit, the controller declares the vhost first, then declares the limits. The flake happened when a "limits" tests ran before the "deletion" tests, and left behind a value for `vhostLimits` variable. This variable is taken unconditionally to initialise a vhost variable (as it should). The flake is simply fixed by setting the `vhostLimits` variable back to `nil` after each "limits" test. Additionally, the "creation" tests should not delete the objects after each test suite, because the fake client is not prepared to return appropriate responses to the delete requests, and that would leave the managers in an infinite reconcile loop, which can delay manager shutdown after each test.
1 parent cffee68 commit 1bcc485

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

controllers/vhost_controller_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ var _ = Describe("vhost-controller", func() {
116116
})
117117

118118
Context("creation", func() {
119-
AfterEach(func() {
120-
Expect(k8sClient.Delete(ctx, &vhost)).To(Succeed())
121-
})
122-
123119
When("the RabbitMQ Client returns a HTTP error response", func() {
124120
BeforeEach(func() {
125121
vhostName = "test-http-error"
@@ -188,6 +184,11 @@ var _ = Describe("vhost-controller", func() {
188184
Context("vhost limits", func() {
189185
var connections, queues int32
190186

187+
AfterEach(func() {
188+
// Must reset the vhost limits to avoid test pollution
189+
vhostLimits = nil
190+
})
191+
191192
When("vhost limits are provided", func() {
192193
BeforeEach(func() {
193194
connections = 708

0 commit comments

Comments
 (0)