Bläddra i källkod

test(kafka consumer): fix flaky test

Thales Macedo Garitezi 1 år sedan
förälder
incheckning
76d76ab449
1 ändrade filer med 17 tillägg och 7 borttagningar
  1. 17 7
      apps/emqx_bridge_kafka/test/emqx_bridge_v2_kafka_consumer_SUITE.erl

+ 17 - 7
apps/emqx_bridge_kafka/test/emqx_bridge_v2_kafka_consumer_SUITE.erl

@@ -560,13 +560,23 @@ t_pretty_api_dry_run_reason(Config) ->
                 ),
                 ?assertMatch({400, _}, Res),
                 {400, #{<<"message">> := Msg}} = Res,
-                ?assertEqual(
-                    match,
-                    re:run(Msg, <<"Leader for partition . unavailable; reason: ">>, [
-                        {capture, none}
-                    ]),
-                    #{message => Msg}
-                )
+                LeaderUnavailable =
+                    match ==
+                        re:run(
+                            Msg,
+                            <<"Leader for partition . unavailable; reason: ">>,
+                            [{capture, none}]
+                        ),
+                %% In CI, if this tests runs soon enough, Kafka may not be stable yet, and
+                %% this failure might occur.
+                CoordinatorFailure =
+                    match ==
+                        re:run(
+                            Msg,
+                            <<"shutdown,coordinator_failure">>,
+                            [{capture, none}]
+                        ),
+                ?assert(LeaderUnavailable or CoordinatorFailure, #{message => Msg})
             end),
             %% Wait for recovery; avoids affecting other test cases due to Kafka restabilizing...
             ?retry(