fix(test): fix flaky test

This commit is contained in:
Thales Macedo Garitezi 2022-03-30 14:27:32 -03:00
parent c0d2243e72
commit f425665449
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 8 additions and 6 deletions

View File

@ -158,14 +158,16 @@ auth_header_() ->
{"Authorization", "Basic " ++ Basic}.
restart_monitor() ->
erlang:exit(erlang:whereis(emqx_dashboard_monitor), killed),
?assertEqual(ok, wait_new_monitor(10)).
OldMonitor = erlang:whereis(emqx_dashboard_monitor),
erlang:exit(OldMonitor, killed),
?assertEqual(ok, wait_new_monitor(OldMonitor, 10)).
wait_new_monitor(Count) when Count =< 0 -> timeout;
wait_new_monitor(Count) ->
case is_pid(erlang:whereis(emqx_dashboard_monitor)) of
wait_new_monitor(_OldMonitor, Count) when Count =< 0 -> timeout;
wait_new_monitor(OldMonitor, Count) ->
NewMonitor = erlang:whereis(emqx_dashboard_monitor),
case is_pid(NewMonitor) andalso NewMonitor =/= OldMonitor of
true -> ok;
false ->
timer:sleep(100),
wait_new_monitor(Count - 1)
wait_new_monitor(OldMonitor, Count - 1)
end.