From d6288a0b7011e2ef08081945feb085467bc397c9 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Thu, 25 Nov 2021 17:15:07 -0300 Subject: [PATCH] test(flakiness): prevent possible flakiness in test If the spawned process doesn't have enough time to be properly set up, the returned stacktrace may be empty, making the test fail. By synchronizing the startup, we know that the process will have a proper stacktrace by the time of the assertion. --- apps/emqx/test/emqx_sys_mon_SUITE.erl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/emqx/test/emqx_sys_mon_SUITE.erl b/apps/emqx/test/emqx_sys_mon_SUITE.erl index b62aa16ef..0286800de 100644 --- a/apps/emqx/test/emqx_sys_mon_SUITE.erl +++ b/apps/emqx/test/emqx_sys_mon_SUITE.erl @@ -93,7 +93,13 @@ t_procinfo(_) -> ?assertEqual([{pid, self()}], emqx_sys_mon:procinfo(self())). t_procinfo_initial_call_and_stacktrace(_) -> - SomePid = proc_lib:spawn(?MODULE, some_function, [arg1, arg2]), + SomePid = proc_lib:spawn(?MODULE, some_function, [self(), arg2]), + receive + {spawned, SomePid} -> + ok + after 100 -> + error(process_not_spawned) + end, ProcInfo = emqx_sys_mon:procinfo(SomePid), ?assertEqual( {?MODULE, some_function, ['Argument__1','Argument__2']}, @@ -139,7 +145,8 @@ validate_sys_mon_info(PidOrPort, SysMonName, ValidateInfo, InfoOrPort) -> fmt(Fmt, Args) -> lists:flatten(io_lib:format(Fmt, Args)). -some_function(_Arg1, _Arg2) -> +some_function(Parent, _Arg2) -> + Parent ! {spawned, self()}, receive stop -> ok