rabbitmq / ra

A Raft implementation for Erlang and Elixir that strives to be efficient and make it easier to use multiple Raft clusters in a single system.
Other
798 stars 93 forks source link

ra_SUITE: Fix flake in consistent_query_leader_change #423

Closed the-mikedavis closed 4 months ago

the-mikedavis commented 4 months ago

The line:

{ok, 9, B} = ra:consistent_query(B, fun(S) -> S end)

would flake because B might fail to become the leader. ra:transfer_leadership/2 is asynchronous and fallible and in cases where the test flaked, B was recovering and catching up to the latest changes, so it didn't assume leadership.

We can wait for B to catch up enough that it should win pre-votes and then wait for it to assume leadership before asserting that B is the leader to fix the flake.