فهرست منبع

test(emqx_bridge_mqtt): fix race condition

Zaiming Shi 4 سال پیش
والد
کامیت
2ffa71abde

+ 2 - 1
apps/emqx_bridge_mqtt/test/emqx_bridge_stub_conn.erl

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

+ 9 - 0
apps/emqx_bridge_mqtt/test/emqx_bridge_worker_SUITE.erl

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