test: refactor test structure

This commit is contained in:
Thales Macedo Garitezi 2024-08-01 15:34:58 -03:00
parent 3162fe7a27
commit bba9d085d6
3 changed files with 31 additions and 34 deletions

View File

@ -1154,7 +1154,7 @@ t_bridges_probe(Config) ->
?assertMatch( ?assertMatch(
{ok, 400, #{ {ok, 400, #{
<<"code">> := <<"TEST_FAILED">>, <<"code">> := <<"TEST_FAILED">>,
<<"message">> := <<"Connection refused">> <<"message">> := <<"Connection refused", _/binary>>
}}, }},
request_json( request_json(
post, post,

View File

@ -563,6 +563,7 @@ log_connect_error_reason(Level, Reason, Name) ->
explain_error(econnrefused) -> explain_error(econnrefused) ->
<< <<
"Connection refused. "
"This error indicates that your connection attempt to the MQTT server was rejected. " "This error indicates that your connection attempt to the MQTT server was rejected. "
"In simpler terms, the server you tried to connect to refused your request. " "In simpler terms, the server you tried to connect to refused your request. "
"There can be multiple reasons for this. " "There can be multiple reasons for this. "

View File

@ -27,8 +27,6 @@
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl"). -include_lib("snabbkaffe/include/snabbkaffe.hrl").
-import(emqx_common_test_helpers, [on_exit/1]).
%% output functions %% output functions
-export([inspect/3]). -export([inspect/3]).
@ -1027,6 +1025,8 @@ t_mqtt_conn_bridge_egress_async_reconnect(_) ->
ct:sleep(1000), ct:sleep(1000),
%% stop the listener 1883 to make the bridge disconnected %% stop the listener 1883 to make the bridge disconnected
?check_trace(
begin
ok = emqx_listeners:stop_listener('tcp:default'), ok = emqx_listeners:stop_listener('tcp:default'),
ct:sleep(1500), ct:sleep(1500),
?assertMatch( ?assertMatch(
@ -1051,16 +1051,12 @@ t_mqtt_conn_bridge_egress_async_reconnect(_) ->
|| I <- lists:seq(1, N), || I <- lists:seq(1, N),
Payload <- [integer_to_binary(I)] Payload <- [integer_to_binary(I)]
], ],
ok
Trace = snabbkaffe:collect_trace(50),
?assert(
lists:any(
fun(K) ->
maps:get(msg, K, not_found) =:=
emqx_bridge_mqtt_connector_econnrefused_error
end, end,
Trace fun(Trace) ->
) ?assertMatch([_ | _], ?of_kind(emqx_bridge_mqtt_connector_econnrefused_error, Trace)),
ok
end
), ),
ok. ok.