Skip to content

Commit e038321

Browse files
committed
Add retries to CrtHttpClientApiCallTimeoutTest for race condition and BatchingEfficiencyUnderLoadTest with sleep to allow batch flush completion
1 parent e59ccb0 commit e038321

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
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;
37+
import software.amazon.awssdk.crt.http.HttpException;
3738

3839
@WireMockTest
3940
public class CrtHttpClientApiCallTimeoutTest {
@@ -49,7 +50,7 @@ public void setup(WireMockRuntimeInfo wiremock) {
4950
.credentialsProvider(() -> AwsBasicCredentials.create("akid", "skid"));
5051
}
5152

52-
@Test
53+
@RetryableTest(maxRetries = 3)
5354
void apiCallAttemptExceeded_shouldThrowApiCallAttemptTimeoutException() {
5455
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}").withFixedDelay(2000)));
5556
try (ProtocolRestJsonClient client =
@@ -61,7 +62,7 @@ void apiCallAttemptExceeded_shouldThrowApiCallAttemptTimeoutException() {
6162
}
6263
}
6364

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

0 commit comments

Comments
 (0)