Merge pull request #8107 from zmstone/0531-test-fix-flaky-test-case

test: wait for listener to be ready before running test case
This commit is contained in:
Zaiming (Stone) Shi 2022-06-02 15:52:40 +01:00 committed by GitHub
commit a272951415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -21,6 +21,7 @@
-include("emqx_mqtt.hrl"). -include("emqx_mqtt.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
%% APIs %% APIs
-export([ -export([
@ -193,6 +194,7 @@ start_listener(Type, ListenerName, #{bind := Bind} = Conf) ->
), ),
ok; ok;
{ok, _} -> {ok, _} ->
?tp(listener_started, #{type => Type, bind => Bind}),
console_print( console_print(
"Listener ~ts on ~ts started.~n", "Listener ~ts on ~ts started.~n",
[listener_id(Type, ListenerName), format_addr(Bind)] [listener_id(Type, ListenerName), format_addr(Bind)]

View File

@ -22,6 +22,7 @@
-include_lib("emqx/include/emqx.hrl"). -include_lib("emqx/include/emqx.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
-define(TOPIC, <<"t">>). -define(TOPIC, <<"t">>).
-define(CNT, 100). -define(CNT, 100).
@ -32,7 +33,17 @@
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
?check_trace(
?wait_async_action(
emqx_common_test_helpers:start_apps([]), emqx_common_test_helpers:start_apps([]),
#{?snk_kind := listener_started, bind := 1883},
timer:seconds(5)
),
fun(Trace) ->
%% more than one listener
?assertMatch([_ | _], ?of_kind(listener_started, Trace))
end
),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->