Fix off-by-one error in an index shard test

There is an off-by-one error in this test. It leads to the recovery
thread never being started, and that means joining on it will wait
indefinitely. This commit addresses that by fixing the off-by-one error.

Relates #42325
This commit is contained in:
Jason Tedor 2019-05-21 19:13:39 -04:00
parent 6808951e6f
commit b510402b67
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 10 additions and 9 deletions

View File

@ -1744,7 +1744,6 @@ public class IndexShardTests extends IndexShardTestCase {
closeShards(shard);
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/42325")
public void testDelayedOperationsBeforeAndAfterRelocated() throws Exception {
final IndexShard shard = newStartedShard(true);
IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(shard.routingEntry(), "other_node"));
@ -1762,12 +1761,11 @@ public class IndexShardTests extends IndexShardTestCase {
recoveryThread.start();
final int numberOfAcquisitions = randomIntBetween(1, 10);
final int recoveryIndex = randomIntBetween(1, numberOfAcquisitions);
final List<Runnable> assertions = new ArrayList<>(numberOfAcquisitions);
final int recoveryIndex = randomIntBetween(0, numberOfAcquisitions - 1);
for (int i = 0; i < numberOfAcquisitions; i++) {
final PlainActionFuture<Releasable> onLockAcquired;
final Runnable assertion;
if (i < recoveryIndex) {
final AtomicBoolean invoked = new AtomicBoolean();
onLockAcquired = new PlainActionFuture<Releasable>() {
@ -1785,26 +1783,29 @@ public class IndexShardTests extends IndexShardTestCase {
}
};
assertion = () -> assertTrue(invoked.get());
assertions.add(() -> assertTrue(invoked.get()));
} else if (recoveryIndex == i) {
startRecovery.countDown();
relocationStarted.await();
onLockAcquired = new PlainActionFuture<>();
assertion = () -> {
assertions.add(() -> {
final ExecutionException e = expectThrows(ExecutionException.class, () -> onLockAcquired.get(30, TimeUnit.SECONDS));
assertThat(e.getCause(), instanceOf(ShardNotInPrimaryModeException.class));
assertThat(e.getCause(), hasToString(containsString("shard is not in primary mode")));
};
});
} else {
onLockAcquired = new PlainActionFuture<>();
assertion = () -> {
assertions.add(() -> {
final ExecutionException e = expectThrows(ExecutionException.class, () -> onLockAcquired.get(30, TimeUnit.SECONDS));
assertThat(e.getCause(), instanceOf(ShardNotInPrimaryModeException.class));
assertThat(e.getCause(), hasToString(containsString("shard is not in primary mode")));
};
});
}
shard.acquirePrimaryOperationPermit(onLockAcquired, ThreadPool.Names.WRITE, "i_" + i);
}
for (final Runnable assertion : assertions) {
assertion.run();
}