Skip to content

Relax assertion about retry count for S3 repos #88801

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

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 @@ -34,6 +34,7 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.repositories.blobstore.AbstractBlobContainerRetriesTestCase;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.mockito.Mockito;
Expand All @@ -55,12 +56,15 @@
import static org.elasticsearch.repositories.s3.S3ClientSettings.ENDPOINT_SETTING;
import static org.elasticsearch.repositories.s3.S3ClientSettings.MAX_RETRIES_SETTING;
import static org.elasticsearch.repositories.s3.S3ClientSettings.READ_TIMEOUT_SETTING;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;

/**
* This class tests how a {@link S3BlobContainer} and its underlying AWS S3 client are retrying requests when reading or writing blobs.
Expand Down Expand Up @@ -516,6 +520,12 @@ public void handle(HttpExchange exchange) throws IOException {
}
}

@Override
protected Matcher<Integer> getMaxRetriesMatcher(int maxRetries) {
// some attempts make meaningful progress and do not count towards the max retry limit
return allOf(greaterThanOrEqualTo(maxRetries), lessThanOrEqualTo(S3RetryingInputStream.MAX_SUPPRESSED_EXCEPTIONS));
}

/**
* Asserts that an InputStream is fully consumed, or aborted, when it is closed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ public void testReadBlobWithReadTimeouts() {
.or(containsString("Read timed out"))
.or(containsString("unexpected end of file from server"))
);
assertThat(exception.getSuppressed().length, equalTo(maxRetries));
assertThat(exception.getSuppressed().length, getMaxRetriesMatcher(maxRetries));
}

protected org.hamcrest.Matcher<Integer> getMaxRetriesMatcher(int maxRetries) {
return equalTo(maxRetries);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

}

public void testReadBlobWithNoHttpResponse() {
Expand All @@ -304,7 +308,6 @@ public void testReadBlobWithNoHttpResponse() {
);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/88666")
public void testReadBlobWithPrematureConnectionClose() {
final int maxRetries = randomInt(20);
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null);
Expand All @@ -331,7 +334,7 @@ public void testReadBlobWithPrematureConnectionClose() {
containsString("premature end of content-length delimited message body")
).or(containsString("connection closed prematurely"))
);
assertThat(exception.getSuppressed().length, equalTo(Math.min(10, maxRetries)));
assertThat(exception.getSuppressed().length, getMaxRetriesMatcher(Math.min(10, maxRetries)));
}

protected static byte[] randomBlobContent() {
Expand Down