Skip to content

Reduce Khepri test flakes #11917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deps/rabbitmq_ct_helpers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rabbitmq_app(
"//deps/rabbit_common:erlang_app",
"@meck//:erlang_app",
"@proper//:erlang_app",
"@ra//:erlang_app",
],
)

Expand Down
27 changes: 26 additions & 1 deletion deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
test_writer/1,
user/1,

configured_metadata_store/1
configured_metadata_store/1,
await_metadata_store_consistent/2
]).

%% Internal functions exported to be used by rpc:call/4.
Expand Down Expand Up @@ -990,6 +991,30 @@ enable_khepri_metadata_store(Config, FFs0) ->
end
end, Config, FFs).

%% Waits until the metadata store replica on Node is up to date with the leader.
await_metadata_store_consistent(Config, Node) ->
case configured_metadata_store(Config) of
mnesia ->
ok;
{khepri, _} ->
RaClusterName = rabbit_khepri:get_ra_cluster_name(),
Leader = rpc(Config, Node, ra_leaderboard, lookup_leader, [RaClusterName]),
LastAppliedLeader = ra_last_applied(Leader),

NodeName = get_node_config(Config, Node, nodename),
ServerId = {RaClusterName, NodeName},
rabbit_ct_helpers:eventually(
?_assert(
begin
LastApplied = ra_last_applied(ServerId),
is_integer(LastApplied) andalso LastApplied >= LastAppliedLeader
end))
end.

ra_last_applied(ServerId) ->
#{last_applied := LastApplied} = ra:key_metrics(ServerId),
LastApplied.

rewrite_node_config_file(Config, Node) ->
NodeConfig = get_node_config(Config, Node),
I = if
Expand Down
4 changes: 3 additions & 1 deletion deps/rabbitmq_mqtt/test/shared_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
rpc_all/4,
get_node_config/3,
drain_node/2,
revive_node/2
revive_node/2,
await_metadata_store_consistent/2
]).
-import(rabbit_ct_helpers,
[eventually/3,
Expand Down Expand Up @@ -1128,6 +1129,7 @@ rabbit_mqtt_qos0_queue_kill_node(Config) ->
SubscriberId = <<"subscriber">>,
Sub0 = connect(SubscriberId, Config, 0, []),
{ok, _, [0]} = emqtt:subscribe(Sub0, Topic1, qos0),
ok = await_metadata_store_consistent(Config, 2),
ok = emqtt:publish(Pub, Topic1, <<"m0">>, qos0),
ok = expect_publishes(Sub0, Topic1, [<<"m0">>]),

Expand Down
Loading