Skip to content

Commit 664d98b

Browse files
authored
Fix GMSPersStateTests#testDataOnlyNodePersistence (#83900) (#83962)
This test assumes that we call `setLastAcceptedState` at least once in the loop, but very rarely this would not be the case. This fix ensures that we always persist at least one state. Closes #83759
1 parent 32fbdad commit 664d98b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/src/test/java/org/elasticsearch/gateway/GatewayMetaStatePersistedStateTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ public void testDataOnlyNodePersistence() throws Exception {
480480
// generate a series of updates and check if batching works
481481
final String indexName = randomAlphaOfLength(10);
482482
long currentTerm = state.term();
483+
boolean wroteState = false;
483484
final int iterations = randomIntBetween(1, 1000);
484485
for (int i = 0; i < iterations; i++) {
485-
if (rarely()) {
486+
final boolean mustWriteState = wroteState == false && i == iterations - 1;
487+
if (rarely() && mustWriteState == false) {
486488
// bump term
487489
currentTerm = currentTerm + (rarely() ? randomIntBetween(1, 5) : 0L);
488490
persistedState.setCurrentTerm(currentTerm);
@@ -496,8 +498,10 @@ public void testDataOnlyNodePersistence() throws Exception {
496498
Metadata.builder().coordinationMetadata(createCoordinationMetadata(term)).put(indexMetadata, false).build()
497499
);
498500
persistedState.setLastAcceptedState(state);
501+
wroteState = true;
499502
}
500503
}
504+
assertTrue(wroteState); // must write it at least once
501505
assertEquals(currentTerm, persistedState.getCurrentTerm());
502506
assertClusterStateEqual(state, persistedState.getLastAcceptedState());
503507
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));

0 commit comments

Comments
 (0)