瀏覽代碼

chore: fix flaky tests

JianBo He 2 年之前
父節點
當前提交
891ecc179d
共有 1 個文件被更改,包括 16 次插入7 次删除
  1. 16 7
      apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl

+ 16 - 7
apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl

@@ -111,7 +111,7 @@ groups() ->
     ].
     ].
 
 
 suite() ->
 suite() ->
-    [{timetrap, {seconds, 60}}].
+    [{timetrap, {seconds, 120}}].
 
 
 init_per_suite(Config) ->
 init_per_suite(Config) ->
     Config.
     Config.
@@ -1329,15 +1329,24 @@ t_cluster_later_join_metrics(Config) ->
             ok = erpc:call(OtherNode, ekka, join, [PrimaryNode]),
             ok = erpc:call(OtherNode, ekka, join, [PrimaryNode]),
             %% Check metrics; shouldn't crash even if the bridge is not
             %% Check metrics; shouldn't crash even if the bridge is not
             %% ready on the node that just joined the cluster.
             %% ready on the node that just joined the cluster.
+
+            %% assert: wait for the bridge to be ready on the other node.
+            fun
+                WaitConfSync(0) ->
+                    throw(waiting_config_sync_timeout);
+                WaitConfSync(N) ->
+                    timer:sleep(1000),
+                    case erpc:call(OtherNode, emqx_bridge, list, []) of
+                        [] -> WaitConfSync(N - 1);
+                        [_] -> ok
+                    end
+            end(
+                60
+            ),
             ?assertMatch(
             ?assertMatch(
                 {ok, 200, #{
                 {ok, 200, #{
                     <<"metrics">> := #{<<"success">> := _},
                     <<"metrics">> := #{<<"success">> := _},
-                    %% TODO: Why the node2 returns {error, bridge_not_found}?
-                    %% ct:pal("node: ~p, bridges: ~p~n", [
-                    %%    OtherNode, erpc:call(OtherNode, emqx_bridge, list, [])
-                    %% ]),
-                    %%<<"node_metrics">> := [#{<<"metrics">> := #{}}, #{<<"metrics">> := #{}} | _]
-                    <<"node_metrics">> := [#{<<"metrics">> := #{}} | _]
+                    <<"node_metrics">> := [#{<<"metrics">> := #{}}, #{<<"metrics">> := #{}} | _]
                 }},
                 }},
                 request_json(get, uri(["bridges", BridgeID, "metrics"]), Config)
                 request_json(get, uri(["bridges", BridgeID, "metrics"]), Config)
             ),
             ),