test(emqx_bridge_mqtt): fix race condition

This commit is contained in:
Zaiming Shi 2021-04-20 21:48:28 +02:00 committed by Zaiming (Stone) Shi
parent 186dfd04a7
commit 2ffa71abde
2 changed files with 11 additions and 1 deletions

View File

@ -27,7 +27,8 @@
-type ack_ref() :: emqx_bridge_worker:ack_ref().
-type batch() :: emqx_bridge_worker:batch().
start(Cfg) ->
start(#{client_pid := Pid} = Cfg) ->
Pid ! {self(), ?MODULE, ready},
{ok, Cfg}.
stop(_) -> ok.

View File

@ -194,6 +194,12 @@ t_stub_normal(Config) when is_list(Config) ->
client_pid => self()
},
{ok, Pid} = emqx_bridge_worker:start_link(?FUNCTION_NAME, Cfg),
receive
{Pid, emqx_bridge_stub_conn, ready} -> ok
after
5000 ->
error(timeout)
end,
ClientId = <<"ClientId">>,
try
{ok, ConnPid} = emqtt:start_link([{clientid, ClientId}]),
@ -203,6 +209,9 @@ t_stub_normal(Config) when is_list(Config) ->
{stub_message, WorkerPid, BatchRef, _Batch} ->
WorkerPid ! {batch_ack, BatchRef},
ok
after
5000 ->
error(timeout)
end,
?SNK_WAIT(inflight_drained),
?SNK_WAIT(replayq_drained),