Skip to content

Commit

Permalink
Fix off-by-one error in an index shard test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jasontedor committed May 21, 2019
1 parent de2180c commit deecdec
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1732,12 +1732,11 @@ public void testDelayedOperationsBeforeAndAfterRelocated() throws Exception {
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>() {
Expand All @@ -1755,26 +1754,29 @@ public void onFailure(Exception e) {
}

};
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();
}

Expand Down

0 comments on commit deecdec

Please sign in to comment.