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,40 +1025,38 @@ 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
ok = emqx_listeners:stop_listener('tcp:default'), ?check_trace(
ct:sleep(1500), begin
?assertMatch( ok = emqx_listeners:stop_listener('tcp:default'),
#{<<"status">> := Status} when ct:sleep(1500),
Status == <<"connecting">> orelse Status == <<"disconnected">>, ?assertMatch(
request_bridge(BridgeIDEgress) #{<<"status">> := Status} when
), Status == <<"connecting">> orelse Status == <<"disconnected">>,
request_bridge(BridgeIDEgress)
),
%% start the listener 1883 to make the bridge reconnected %% start the listener 1883 to make the bridge reconnected
ok = emqx_listeners:start_listener('tcp:default'), ok = emqx_listeners:start_listener('tcp:default'),
timer:sleep(1500), timer:sleep(1500),
?assertMatch( ?assertMatch(
#{<<"status">> := <<"connected">>}, #{<<"status">> := <<"connected">>},
request_bridge(BridgeIDEgress) request_bridge(BridgeIDEgress)
), ),
N = stop_publisher(Publisher), N = stop_publisher(Publisher),
%% all those messages should eventually be delivered %% all those messages should eventually be delivered
[ [
assert_mqtt_msg_received(RemoteTopic, Payload) assert_mqtt_msg_received(RemoteTopic, Payload)
|| 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), end,
?assert( fun(Trace) ->
lists:any( ?assertMatch([_ | _], ?of_kind(emqx_bridge_mqtt_connector_econnrefused_error, Trace)),
fun(K) -> ok
maps:get(msg, K, not_found) =:= end
emqx_bridge_mqtt_connector_econnrefused_error
end,
Trace
)
), ),
ok. ok.