Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky RemoteIndexRecoveryIT testRerouteRecovery test #9580 #11918

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,12 @@ public void testRerouteRecovery() throws Exception {

logger.info("--> waiting for recovery to start both on source and target");
final Index index = resolveIndex(INDEX_NAME);
assertBusy(() -> {
assertBusyWithFixedSleepTime(() -> {
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeA);
assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsSource(), equalTo(1));
indicesService = internalCluster().getInstance(IndicesService.class, nodeB);
assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsTarget(), equalTo(1));
});
}, TimeValue.timeValueSeconds(10), TimeValue.timeValueMillis(500));

logger.info("--> request recoveries");
RecoveryResponse response = client().admin().indices().prepareRecoveries(INDEX_NAME).execute().actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,4 @@ public void testDisconnectsDuringRecovery() {
public void testReplicaRecovery() {

}

@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/9580")
public void testRerouteRecovery() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.time.DateUtils;
import org.opensearch.common.time.FormatNames;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.MockBigArrays;
import org.opensearch.common.util.MockPageCacheRecycler;
import org.opensearch.common.util.concurrent.ThreadContext;
Expand Down Expand Up @@ -1095,6 +1096,38 @@ public static void assertBusy(CheckedRunnable<Exception> codeBlock, long maxWait
}
}

/**
* Runs the code block for the provided max wait time and sleeping for fixed sleep time, waiting for no assertions to trip.
*/
public static void assertBusyWithFixedSleepTime(CheckedRunnable<Exception> codeBlock, TimeValue maxWaitTime, TimeValue sleepTime)
throws Exception {
long maxTimeInMillis = maxWaitTime.millis();
long sleepTimeInMillis = sleepTime.millis();
if (sleepTimeInMillis > maxTimeInMillis) {
throw new IllegalArgumentException("sleepTime is more than the maxWaitTime");
}
long sum = 0;
List<AssertionError> failures = new ArrayList<>();
while (sum <= maxTimeInMillis) {
try {
codeBlock.run();
return;
} catch (AssertionError e) {
failures.add(e);
}
sum += sleepTimeInMillis;
Thread.sleep(sleepTimeInMillis);
}
try {
codeBlock.run();
} catch (AssertionError e) {
for (AssertionError failure : failures) {
e.addSuppressed(failure);
}
throw e;
}
ashking94 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Periodically execute the supplied function until it returns true, or a timeout
* is reached. This version uses a timeout of 10 seconds. If at all possible,
Expand Down
Loading