Skip to content

Commit 2392409

Browse files
authored
Add retries to CrtHttpClientApiCallTimeoutTest for race condition and BatchingEfficiencyUnderLoadTest with sleep to allow batch flush completion (#6609)
1 parent 27a356b commit 2392409

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

services/sqs/src/test/java/software/amazon/awssdk/services/sqs/batchmanager/BatchingEfficiencyUnderLoadTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import java.util.stream.Collectors;
3232
import org.junit.jupiter.api.AfterEach;
3333
import org.junit.jupiter.api.BeforeEach;
34-
import org.junit.jupiter.api.Test;
3534
import org.junit.jupiter.api.extension.RegisterExtension;
3635
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3736
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
3837
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
38+
import software.amazon.awssdk.testutils.retry.RetryableTest;
3939

4040

4141
/**
@@ -84,7 +84,7 @@ void tearDown() {
8484
/**
8585
* Test runs heavy load and expects average batch sizes to be close to max.
8686
*/
87-
@Test
87+
@RetryableTest(maxRetries = 3)
8888
void sendMessage_whenHighLoadScenario_shouldEfficientlyBatchMessages() throws Exception {
8989
int expectedBatchSize = 25; // more than double the actual max of 10
9090
int rateLimit = 1000 / SEND_FREQUENCY_MILLIS * expectedBatchSize;
@@ -126,7 +126,7 @@ void sendMessage_whenHighLoadScenario_shouldEfficientlyBatchMessages() throws Ex
126126
/**
127127
* Test runs a load that should cause an average batch size of 5.
128128
*/
129-
@Test
129+
@RetryableTest(maxRetries = 3)
130130
void sendMessage_whenMediumLoadScenario_shouldCreateHalfSizeBatches() throws Exception {
131131
int expectedBatchSize = 5;
132132
int rateLimit = 1000 / SEND_FREQUENCY_MILLIS * expectedBatchSize;
@@ -157,7 +157,7 @@ void sendMessage_whenMediumLoadScenario_shouldCreateHalfSizeBatches() throws Exc
157157
.isLessThan(messageCount / 3d);
158158
}
159159

160-
@Test
160+
@RetryableTest(maxRetries = 3)
161161
void sendMessage_whenLowLoadScenario_shouldCreateSmallBatches() throws Exception {
162162
int expectedBatchSize = 1;
163163
int rateLimit = 1000 / SEND_FREQUENCY_MILLIS * expectedBatchSize;
@@ -217,5 +217,8 @@ private void runThroughputTest(int messageCount, int rateLimit) throws Interrupt
217217

218218
executor.shutdown();
219219
executor.awaitTermination(10, TimeUnit.SECONDS);
220+
221+
// Wait for batch manager to flush all pending batches
222+
Thread.sleep(SEND_FREQUENCY_MILLIS * 3);
220223
}
221224
}

test/protocol-tests/src/test/java/software/amazon/awssdk/protocol/tests/timeout/CrtHttpClientApiCallTimeoutTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import java.net.URI;
2727
import java.time.Duration;
2828
import org.junit.jupiter.api.BeforeEach;
29-
import org.junit.jupiter.api.Test;
3029
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3130
import software.amazon.awssdk.core.exception.ApiCallAttemptTimeoutException;
3231
import software.amazon.awssdk.core.exception.ApiCallTimeoutException;
3332
import software.amazon.awssdk.http.crt.AwsCrtHttpClient;
3433
import software.amazon.awssdk.regions.Region;
3534
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
3635
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClientBuilder;
36+
import software.amazon.awssdk.testutils.retry.RetryableTest;
3737

3838
@WireMockTest
3939
public class CrtHttpClientApiCallTimeoutTest {
@@ -49,7 +49,7 @@ public void setup(WireMockRuntimeInfo wiremock) {
4949
.credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"));
5050
}
5151

52-
@Test
52+
@RetryableTest(maxRetries = 3)
5353
void apiCallAttemptExceeded_shouldThrowApiCallAttemptTimeoutException() {
5454
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}").withFixedDelay(2000)));
5555
try (ProtocolRestJsonClient client =
@@ -61,7 +61,7 @@ void apiCallAttemptExceeded_shouldThrowApiCallAttemptTimeoutException() {
6161
}
6262
}
6363

64-
@Test
64+
@RetryableTest(maxRetries = 3)
6565
void apiCallExceeded_shouldThrowApiCallAttemptTimeoutException() {
6666
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}").withFixedDelay(2000)));
6767
try (ProtocolRestJsonClient client = clientBuilder.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(10)))

0 commit comments

Comments
 (0)