@@ -44,7 +44,7 @@ import (
44
44
45
45
const (
46
46
// clustersRequired is the number of clusters required in this E2E test.
47
- clustersRequired = 2
47
+ clustersRequired = 3
48
48
// testName is the name of this E2E test.
49
49
testName = "NETWORK"
50
50
// StressMax is the maximum number of stress iterations.
@@ -126,16 +126,29 @@ var _ = Describe("Liqo E2E", func() {
126
126
When ("\" liqoctl test network\" runs" , func () {
127
127
It ("should succeed both before and after gateway pods restart" , func () {
128
128
// Run the tests.
129
- Eventually (runLiqoctlNetworkTests (defaultArgs ), timeout , interval ).Should (Succeed ())
129
+ Eventually (func () error {
130
+ return runLiqoctlNetworkTests (defaultArgs )
131
+ }, timeout , interval ).Should (Succeed ())
130
132
131
133
// Restart the gateway pods.
132
134
for i := range testContext .Clusters {
133
135
RestartPods (testContext .Clusters [i ].ControllerClient )
134
136
}
135
137
138
+ // Check if there is only one active gateway pod per remote cluster.
139
+ for i := range testContext .Clusters {
140
+ numActiveGateway := testContext .Clusters [i ].NumPeeredConsumers + testContext .Clusters [i ].NumPeeredProviders
141
+ Eventually (func () error {
142
+ return checkUniqueActiveGatewayPod (testContext .Clusters [i ].ControllerClient , numActiveGateway )
143
+ }, timeout , interval ).Should (Succeed ())
144
+ }
145
+
136
146
// Run the tests again.
137
- Eventually (runLiqoctlNetworkTests (defaultArgs ), timeout , interval ).Should (Succeed ())
147
+ Eventually (func () error {
148
+ return runLiqoctlNetworkTests (defaultArgs )
149
+ }, timeout , interval ).Should (Succeed ())
138
150
})
151
+
139
152
It ("should succeed both before and after gateway pods restart (stress gateway deletion and run basic tests)" , func () {
140
153
args := defaultArgs
141
154
args .basic = true
@@ -146,12 +159,22 @@ var _ = Describe("Liqo E2E", func() {
146
159
RestartPods (testContext .Clusters [j ].ControllerClient )
147
160
}
148
161
162
+ // Check if there is only one active gateway pod per remote cluster.
163
+ for j := range testContext .Clusters {
164
+ numActiveGateway := testContext .Clusters [j ].NumPeeredConsumers + testContext .Clusters [j ].NumPeeredProviders
165
+ Eventually (func () error {
166
+ return checkUniqueActiveGatewayPod (testContext .Clusters [j ].ControllerClient , numActiveGateway )
167
+ }, timeout , interval ).Should (Succeed ())
168
+ }
169
+
149
170
if i == stressMax - 1 {
150
171
args .remove = true
151
172
}
152
173
153
174
// Run the tests.
154
- Eventually (runLiqoctlNetworkTests (args ), timeout , interval ).Should (Succeed ())
175
+ Eventually (func () error {
176
+ return runLiqoctlNetworkTests (args )
177
+ }, timeout , interval ).Should (Succeed ())
155
178
}
156
179
})
157
180
})
@@ -299,7 +322,6 @@ func RestartPods(cl client.Client) {
299
322
if err := cl .List (ctx , deploymentList , & client.ListOptions {
300
323
LabelSelector : labels .SelectorFromSet (labels.Set {
301
324
gateway .GatewayComponentKey : gateway .GatewayComponentGateway ,
302
- concurrent .ActiveGatewayKey : concurrent .ActiveGatewayValue ,
303
325
}),
304
326
}); err != nil {
305
327
return err
@@ -314,3 +336,25 @@ func RestartPods(cl client.Client) {
314
336
return nil
315
337
}, timeout , interval ).Should (Succeed ())
316
338
}
339
+
340
+ // checkUniqueActiveGatewayPod checks if there is only one active gateway pod.
341
+ func checkUniqueActiveGatewayPod (cl client.Client , numActiveGateway int ) error {
342
+ // Sleep few seconds to be sure that the new leader is elected.
343
+ time .Sleep (2 * time .Second )
344
+
345
+ podList := & corev1.PodList {}
346
+ if err := cl .List (ctx , podList , & client.ListOptions {
347
+ LabelSelector : labels .SelectorFromSet (labels.Set {
348
+ gateway .GatewayComponentKey : gateway .GatewayComponentGateway ,
349
+ concurrent .ActiveGatewayKey : concurrent .ActiveGatewayValue ,
350
+ }),
351
+ }); err != nil {
352
+ return fmt .Errorf ("unable to list active gateway pods: %w" , err )
353
+ }
354
+
355
+ if len (podList .Items ) != numActiveGateway {
356
+ return fmt .Errorf ("expected %d active gateway pod, got %d" , numActiveGateway , len (podList .Items ))
357
+ }
358
+
359
+ return nil
360
+ }
0 commit comments