Skip to content

Commit 253c5dd

Browse files
authored
Fix testFollowerBehaviour (elastic#96257)
The test was failing when responseDelay == leaderCheckTimeoutMillis. This resulted in scheduling both handling the response and timeout at the same mills and executing them in random order. The fix makes it impossible to reply the same time as request is timeout as the behavior is not deterministic in such case.
1 parent 7b212cd commit 253c5dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/LeaderCheckerTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,14 @@ protected void onSendRequest(long requestId, String action, TransportRequest req
115115
super.onSendRequest(requestId, action, request, node);
116116

117117
final boolean mustSucceed = leaderCheckRetryCount - 1 <= consecutiveFailedRequestsCount;
118-
final long responseDelay = randomLongBetween(0, leaderCheckTimeoutMillis + (mustSucceed ? -1 : 60000));
118+
final long responseDelay = randomValueOtherThan(
119+
leaderCheckTimeoutMillis,
120+
() -> randomLongBetween(0, leaderCheckTimeoutMillis + (mustSucceed ? -1 : 60000))
121+
);
119122
final boolean successResponse = allResponsesFail.get() == false && (mustSucceed || randomBoolean());
120123

121-
if (responseDelay >= leaderCheckTimeoutMillis) {
124+
assert responseDelay != leaderCheckTimeoutMillis;
125+
if (responseDelay > leaderCheckTimeoutMillis) {
122126
timeoutCount.incrementAndGet();
123127
consecutiveFailedRequestsCount += 1;
124128
} else if (successResponse == false) {

0 commit comments

Comments
 (0)