Skip to content

Commit 3700f76

Browse files
authored
Await listener in ReplicationOperationTests#testNoLongerPrimary (#84616) (#84620)
Closes #84610
1 parent 5fd7bcb commit 3700f76

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server/src/test/java/org/elasticsearch/action/support/replication/ReplicationOperationTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@
5252
import java.util.Map;
5353
import java.util.Set;
5454
import java.util.concurrent.ExecutionException;
55+
import java.util.concurrent.TimeUnit;
5556
import java.util.concurrent.atomic.AtomicBoolean;
5657
import java.util.concurrent.atomic.AtomicInteger;
5758
import java.util.concurrent.atomic.AtomicReference;
5859
import java.util.function.Supplier;
5960

6061
import static org.elasticsearch.action.support.replication.ClusterStateCreationUtils.state;
6162
import static org.elasticsearch.action.support.replication.ClusterStateCreationUtils.stateWithActivePrimary;
63+
import static org.hamcrest.Matchers.anyOf;
6264
import static org.hamcrest.Matchers.arrayWithSize;
65+
import static org.hamcrest.Matchers.containsString;
6366
import static org.hamcrest.Matchers.equalTo;
6467
import static org.hamcrest.Matchers.instanceOf;
6568
import static org.hamcrest.Matchers.notNullValue;
@@ -266,7 +269,6 @@ private void addTrackingInfo(
266269
}
267270
}
268271

269-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/84610")
270272
public void testNoLongerPrimary() throws Exception {
271273
final String index = "test";
272274
final ShardId shardId = new ShardId(index, "_na_", 0);
@@ -360,13 +362,19 @@ public void failShard(String message, Exception exception) {
360362
op.execute();
361363

362364
assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true));
363-
assertTrue("listener is not marked as done", listener.isDone());
365+
assertThat(
366+
expectThrows(
367+
ExecutionException.class,
368+
ReplicationOperation.RetryOnPrimaryException.class,
369+
() -> listener.get(10, TimeUnit.SECONDS)
370+
).getMessage(),
371+
anyOf(containsString("demoted while failing replica shard"), containsString("shutting down while failing replica shard"))
372+
);
364373
if (shardActionFailure instanceof ShardStateAction.NoLongerPrimaryShardException) {
365374
assertTrue(primaryFailed.get());
366375
} else {
367376
assertFalse(primaryFailed.get());
368377
}
369-
assertListenerThrows("should throw exception to trigger retry", listener, ReplicationOperation.RetryOnPrimaryException.class);
370378
}
371379

372380
public void testAddedReplicaAfterPrimaryOperation() throws Exception {

0 commit comments

Comments
 (0)