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.
This commit is contained in:
Thales Macedo Garitezi 2021-11-25 17:15:07 -03:00
parent b7928203b8
commit d6288a0b70
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 9 additions and 2 deletions

View File

@ -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