{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.
The line:
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 thatB
is the leader to fix the flake.