Преглед изворни кода

Merge pull request #6310 from emqx/test-fix-possible-flakiness

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.
Thales Macedo Garitezi пре 4 година
родитељ
комит
284619ef86
1 измењених фајлова са 9 додато и 2 уклоњено
  1. 9 2
      apps/emqx/test/emqx_sys_mon_SUITE.erl

+ 9 - 2
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