Skip to content

Commit 537f581

Browse files
committed
Tests: mqtt_shared_SUITE match expected connection
1 parent 5e3765c commit 537f581

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

deps/rabbitmq_mqtt/test/mqtt_shared_SUITE.erl

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,26 +1204,50 @@ management_plugin_connection(Config) ->
12041204
Node = atom_to_binary(get_node_config(Config, 0, nodename)),
12051205

12061206
C1 = connect(ClientId, Config, [{keepalive, KeepaliveSecs}]),
1207-
eventually(?_assertEqual(1, length(http_get(Config, "/connections"))), 1000, 10),
1207+
FilterFun =
1208+
fun(#{client_properties := #{client_id := CId}})
1209+
when CId == ClientId -> true;
1210+
(_) -> false
1211+
end,
1212+
%% Sometimes connections remain open from other testcases,
1213+
%% let's match the one we're looking for
1214+
eventually(
1215+
?_assertMatch(
1216+
[_],
1217+
lists:filter(FilterFun, http_get(Config, "/connections"))),
1218+
1000, 10),
12081219
[#{client_properties := #{client_id := ClientId},
12091220
timeout := KeepaliveSecs,
12101221
node := Node,
1211-
name := ConnectionName}] = http_get(Config, "/connections"),
1222+
name := ConnectionName}] =
1223+
lists:filter(FilterFun, http_get(Config, "/connections")),
12121224
process_flag(trap_exit, true),
12131225
http_delete(Config,
12141226
"/connections/" ++ binary_to_list(uri_string:quote(ConnectionName)),
12151227
?NO_CONTENT),
12161228
await_exit(C1),
1217-
eventually(?_assertEqual([], http_get(Config, "/connections"))),
1229+
eventually(
1230+
?_assertMatch(
1231+
[],
1232+
lists:filter(FilterFun, http_get(Config, "/connections"))),
1233+
1000, 10),
12181234
eventually(?_assertEqual([], all_connection_pids(Config)), 500, 3),
1219-
1235+
12201236
C2 = connect(ClientId, Config, [{keepalive, KeepaliveSecs}]),
1221-
eventually(?_assertEqual(1, length(http_get(Config, "/connections"))), 1000, 10),
1237+
eventually(
1238+
?_assertMatch(
1239+
[_],
1240+
lists:filter(FilterFun, http_get(Config, "/connections"))),
1241+
1000, 10),
12221242
http_delete(Config,
12231243
"/connections/username/guest",
12241244
?NO_CONTENT),
12251245
await_exit(C2),
1226-
eventually(?_assertEqual([], http_get(Config, "/connections"))),
1246+
eventually(
1247+
?_assertMatch(
1248+
[],
1249+
lists:filter(FilterFun, http_get(Config, "/connections"))),
1250+
1000, 10),
12271251
eventually(?_assertEqual([], all_connection_pids(Config)), 500, 3).
12281252

12291253
management_plugin_enable(Config) ->
@@ -1233,10 +1257,22 @@ management_plugin_enable(Config) ->
12331257

12341258
%% If the (web) MQTT connection is established **before** the management plugin is enabled,
12351259
%% the management plugin should still list the (web) MQTT connection.
1236-
C = connect(?FUNCTION_NAME, Config),
1260+
ClientId = atom_to_binary(?FUNCTION_NAME),
1261+
C = connect(ClientId, Config),
12371262
ok = rabbit_ct_broker_helpers:enable_plugin(Config, 0, rabbitmq_management_agent),
12381263
ok = rabbit_ct_broker_helpers:enable_plugin(Config, 0, rabbitmq_management),
1239-
eventually(?_assertEqual(1, length(http_get(Config, "/connections"))), 1000, 10),
1264+
FilterFun =
1265+
fun(#{client_properties := #{client_id := CId}})
1266+
when ClientId == CId -> true;
1267+
(_) -> false
1268+
end,
1269+
%% Sometimes connections remain open from other testcases,
1270+
%% let's match the one we're looking for
1271+
eventually(
1272+
?_assertMatch(
1273+
[_],
1274+
lists:filter(FilterFun, http_get(Config, "/connections"))),
1275+
1000, 10),
12401276

12411277
ok = emqtt:disconnect(C).
12421278

0 commit comments

Comments
 (0)