Skip to content

Commit 2ab890f

Browse files
Fix flake on rabbitmq_mqtt auth_SUITE (#13180)
* Separate invalid client test from the valid one * Apply same changes from pr #13197 * Deal with stalereferences caused by timing issues looking up objects in the DOM * Unlink before assertion
1 parent e8a302a commit 2ab890f

File tree

3 files changed

+69
-34
lines changed

3 files changed

+69
-34
lines changed

deps/rabbitmq_mqtt/test/auth_SUITE.erl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ sub_groups() ->
6868
ssl_user_vhost_parameter_mapping_vhost_does_not_exist,
6969
ssl_user_cert_vhost_mapping_takes_precedence_over_port_vhost_mapping
7070
]},
71+
{ssl_user_with_invalid_client_id_in_cert_san_dns, [],
72+
[invalid_client_id_from_cert_san_dns
73+
]},
7174
{ssl_user_with_client_id_in_cert_san_dns, [],
72-
[client_id_from_cert_san_dns,
73-
invalid_client_id_from_cert_san_dns
75+
[client_id_from_cert_san_dns
7476
]},
7577
{ssl_user_with_client_id_in_cert_san_dns_1, [],
7678
[client_id_from_cert_san_dns_1
@@ -207,7 +209,8 @@ mqtt_config(no_ssl_user) ->
207209
mqtt_config(client_id_propagation) ->
208210
{rabbitmq_mqtt, [{ssl_cert_login, true},
209211
{allow_anonymous, true}]};
210-
mqtt_config(ssl_user_with_client_id_in_cert_san_dns) ->
212+
mqtt_config(T) when T == ssl_user_with_client_id_in_cert_san_dns;
213+
T == ssl_user_with_invalid_client_id_in_cert_san_dns ->
211214
{rabbitmq_mqtt, [{ssl_cert_login, true},
212215
{allow_anonymous, false},
213216
{ssl_cert_client_id_from, subject_alternative_name},
@@ -588,8 +591,8 @@ client_id_from_cert_dn(Config) ->
588591
invalid_client_id_from_cert_san_dns(Config) ->
589592
MqttClientId = <<"other_client_id">>,
590593
{ok, C} = connect_ssl(MqttClientId, Config),
591-
?assertMatch({error, _}, emqtt:connect(C)),
592-
unlink(C).
594+
unlink(C),
595+
{error, {client_identifier_not_valid, _}} = emqtt:connect(C).
593596

594597
ssl_user_vhost_parameter_mapping_success(Config) ->
595598
expect_successful_connection(fun connect_ssl/1, Config).

selenium/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"author": "",
1313
"license": "ISC",
1414
"dependencies": {
15-
"chromedriver": "^130.0.4",
15+
"chromedriver": "^132.0",
1616
"ejs": "^3.1.8",
1717
"express": "^4.18.2",
1818
"geckodriver": "^3.0.2",

selenium/test/pageobjects/BasePage.js

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = class BasePage {
4545
return this.selectOption(SELECT_REFRESH, option)
4646
}
4747
async waitForOverviewTab() {
48+
await this.driver.sleep(250)
4849
return this.waitForDisplayed(OVERVIEW_TAB)
4950
}
5051

@@ -56,27 +57,31 @@ module.exports = class BasePage {
5657
return this.click(CONNECTIONS_TAB)
5758
}
5859
async waitForConnectionsTab() {
60+
await this.driver.sleep(250)
5961
return this.waitForDisplayed(CONNECTIONS_TAB)
6062
}
6163

6264
async clickOnAdminTab () {
6365
return this.click(ADMIN_TAB)
6466
}
6567
async waitForAdminTab() {
68+
await this.driver.sleep(250)
6669
return this.waitForDisplayed(ADMIN_TAB)
6770
}
6871

6972
async clickOnChannelsTab () {
7073
return this.click(CHANNELS_TAB)
7174
}
7275
async waitForChannelsTab() {
76+
await this.driver.sleep(250)
7377
return this.waitForDisplayed(CHANNELS_TAB)
7478
}
7579

7680
async clickOnExchangesTab () {
7781
return this.click(EXCHANGES_TAB)
7882
}
7983
async waitForExchangesTab() {
84+
await this.driver.sleep(250)
8085
return this.waitForDisplayed(EXCHANGES_TAB)
8186
}
8287

@@ -180,42 +185,69 @@ module.exports = class BasePage {
180185
}
181186

182187
async waitForLocated (locator) {
183-
try {
184-
return this.driver.wait(until.elementLocated(locator), this.timeout,
185-
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] seconds locating ' + locator,
186-
this.polling)
187-
}catch(error) {
188-
if (!error.name.includes("NoSuchSessionError")) {
189-
console.error("Failed waitForLocated " + locator + " due to " + error)
190-
}
191-
throw error
192-
}
188+
let attempts = 3
189+
let retry = false
190+
let rethrowError = null
191+
do {
192+
try {
193+
return this.driver.wait(until.elementLocated(locator), this.timeout,
194+
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] seconds locating ' + locator,
195+
this.polling)
196+
}catch(error) {
197+
if (error.name.includes("StaleElementReferenceError")) {
198+
retry = true
199+
}else if (!error.name.includes("NoSuchSessionError")) {
200+
console.error("Failed waitForLocated " + locator + " due to " + error)
201+
retry = false
202+
}
203+
rethrowError = error
204+
}
205+
} while (retry && --attempts > 0)
206+
throw rethrowError
193207
}
194208

195209
async waitForVisible (element) {
196-
try {
197-
return this.driver.wait(until.elementIsVisible(element), this.timeout,
198-
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
199-
this.polling)
200-
}catch(error) {
201-
if (!error.name.includes("NoSuchSessionError")) {
202-
console.error("Failed to find visible element " + element + " due to " + error)
210+
let attempts = 3
211+
let retry = false
212+
let rethrowError = null
213+
do {
214+
try {
215+
return this.driver.wait(until.elementIsVisible(element), this.timeout,
216+
'Timed out after [timeout=' + this.timeout + ';polling=' + this.polling + '] awaiting till visible ' + element,
217+
this.polling)
218+
}catch(error) {
219+
if (error.name.includes("StaleElementReferenceError")) {
220+
retry = true
221+
}else if (!error.name.includes("NoSuchSessionError")) {
222+
console.error("Failed to find visible element " + element + " due to " + error)
223+
retry = false
224+
}
225+
rethrowError = error
203226
}
204-
throw error
205-
}
227+
} while (retry && --attempts > 0)
228+
throw rethrowError
206229
}
207230

208231

209232
async waitForDisplayed (locator) {
210-
if (this.interactionDelay && this.interactionDelay > 0) await this.driver.sleep(this.interactionDelay)
211-
try {
212-
return this.waitForVisible(await this.waitForLocated(locator))
213-
}catch(error) {
214-
if (!error.name.includes("NoSuchSessionError")) {
215-
console.error("Failed to waitForDisplayed " + locator + " due to " + error)
216-
}
217-
throw error
218-
}
233+
let attempts = 3
234+
let retry = false
235+
let rethrowError = null
236+
do {
237+
if (this.interactionDelay && this.interactionDelay > 0) await this.driver.sleep(this.interactionDelay)
238+
try {
239+
return this.waitForVisible(await this.waitForLocated(locator))
240+
}catch(error) {
241+
if (error.name.includes("StaleElementReferenceError")) {
242+
retry = true
243+
}else if (!error.name.includes("NoSuchSessionError")) {
244+
retry = false
245+
console.error("Failed to waitForDisplayed " + locator + " due to " + error)
246+
}
247+
rethrowError = error
248+
}
249+
} while (retry && --attempts > 0 )
250+
throw rethrowError
219251
}
220252

221253
async getText (locator) {

0 commit comments

Comments
 (0)