Skip to content

Commit 32b1fc2

Browse files
authored
[Test] Fix S3ServiceTests.testRetryOn403RetryPolicy (#115993)
AWS's default retry condition defines a list of retryable error status. They are retryable for the custom retryable_403 condition as well. This PR enhances the test to excercise this logic correctly. Resolves: #115986
1 parent 3bc094f commit 32b1fc2

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

modules/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3ServiceTests.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.elasticsearch.repositories.s3;
1010

1111
import com.amazonaws.AmazonWebServiceRequest;
12+
import com.amazonaws.retry.PredefinedRetryPolicies;
1213
import com.amazonaws.services.s3.model.AmazonS3Exception;
1314

1415
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
@@ -19,6 +20,7 @@
1920

2021
import java.io.IOException;
2122

23+
import static org.hamcrest.CoreMatchers.equalTo;
2224
import static org.mockito.Mockito.mock;
2325

2426
public class S3ServiceTests extends ESTestCase {
@@ -47,19 +49,33 @@ public void testRetryOn403RetryPolicy() {
4749
e.setStatusCode(403);
4850
e.setErrorCode("InvalidAccessKeyId");
4951

50-
// Retry on 403 invalid access key id
52+
// AWS default retry condition does not retry on 403
53+
assertFalse(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9)));
54+
55+
// The retryable 403 condition retries on 403 invalid access key id
5156
assertTrue(
5257
S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9))
5358
);
5459

55-
// Not retry if not 403 or not invalid access key id
5660
if (randomBoolean()) {
61+
// Random for another error status that is not 403
5762
e.setStatusCode(randomValueOtherThan(403, () -> between(0, 600)));
63+
// Retryable 403 condition delegates to the AWS default retry condition. Its result must be consistent with the decision
64+
// by the AWS default, e.g. some error status like 429 is retryable by default, the retryable 403 condition respects it.
65+
boolean actual = S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition()
66+
.shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9));
67+
boolean expected = PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(
68+
mock(AmazonWebServiceRequest.class),
69+
e,
70+
between(0, 9)
71+
);
72+
assertThat(actual, equalTo(expected));
5873
} else {
74+
// Not retry for 403 with error code that is not invalid access key id
5975
e.setErrorCode(randomAlphaOfLength(10));
76+
assertFalse(
77+
S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9))
78+
);
6079
}
61-
assertFalse(
62-
S3Service.RETRYABLE_403_RETRY_POLICY.getRetryCondition().shouldRetry(mock(AmazonWebServiceRequest.class), e, between(0, 9))
63-
);
6480
}
6581
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ tests:
160160
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
161161
method: test {p0=ml/inference_crud/Test delete given model referenced by pipeline}
162162
issue: https://github.com/elastic/elasticsearch/issues/115970
163-
- class: org.elasticsearch.repositories.s3.S3ServiceTests
164-
method: testRetryOn403RetryPolicy
165-
issue: https://github.com/elastic/elasticsearch/issues/115986
166163
- class: org.elasticsearch.search.slice.SearchSliceIT
167164
method: testPointInTime
168165
issue: https://github.com/elastic/elasticsearch/issues/115988

0 commit comments

Comments
 (0)