Skip to content

Commit 405cc74

Browse files
authored
Fix stability tests (#5178)
* Fix stability tests * Not failing stability tests based on thread count.
1 parent 768526e commit 405cc74

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/s3/S3AsyncBaseStabilityTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.stability.tests.s3;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static software.amazon.awssdk.stability.tests.utils.StabilityTestRunner.ALLOWED_MAX_PEAK_THREAD_COUNT;
1920

2021
import java.io.File;
2122
import java.io.IOException;
@@ -61,10 +62,18 @@ public abstract class S3AsyncBaseStabilityTest extends AwsTestBase {
6162
.build();
6263
}
6364

65+
private final int allowedPeakThreads;
66+
6467
public S3AsyncBaseStabilityTest(S3AsyncClient testClient) {
68+
this(testClient, ALLOWED_MAX_PEAK_THREAD_COUNT);
69+
}
70+
71+
public S3AsyncBaseStabilityTest(S3AsyncClient testClient, int maxThreadCount) {
72+
this.allowedPeakThreads = maxThreadCount;
6573
this.testClient = testClient;
6674
}
6775

76+
6877
@RetryableTest(maxRetries = 3, retryableException = StabilityTestsRetryableException.class)
6978
public void largeObject_put_get_usingFile() {
7079
String md5Upload = uploadLargeObjectFromFile();
@@ -87,7 +96,7 @@ protected String computeKeyName(int i) {
8796
protected void doGetBucketAcl_lowTpsLongInterval() {
8897
IntFunction<CompletableFuture<?>> future = i -> testClient.getBucketAcl(b -> b.bucket(getTestBucketName()));
8998
String className = this.getClass().getSimpleName();
90-
StabilityTestRunner.newRunner()
99+
StabilityTestRunner.newRunner(allowedPeakThreads)
91100
.testName(className + ".getBucketAcl_lowTpsLongInterval")
92101
.futureFactory(future)
93102
.requestCountPerRun(10)
@@ -99,7 +108,7 @@ protected void doGetBucketAcl_lowTpsLongInterval() {
99108

100109
protected String downloadLargeObjectToFile() {
101110
File randomTempFile = RandomTempFile.randomUncreatedFile();
102-
StabilityTestRunner.newRunner()
111+
StabilityTestRunner.newRunner(allowedPeakThreads)
103112
.testName("S3AsyncStabilityTest.downloadLargeObjectToFile")
104113
.futures(testClient.getObject(b -> b.bucket(getTestBucketName()).key(LARGE_KEY_NAME),
105114
AsyncResponseTransformer.toFile(randomTempFile)))
@@ -120,7 +129,7 @@ protected String uploadLargeObjectFromFile() {
120129
try {
121130
file = new RandomTempFile((long) 2e+9);
122131
String md5 = Md5Utils.md5AsBase64(file);
123-
StabilityTestRunner.newRunner()
132+
StabilityTestRunner.newRunner(allowedPeakThreads)
124133
.testName("S3AsyncStabilityTest.uploadLargeObjectFromFile")
125134
.futures(testClient.putObject(b -> b.bucket(getTestBucketName()).key(LARGE_KEY_NAME),
126135
AsyncRequestBody.fromFile(file)))
@@ -144,7 +153,7 @@ protected void putObject() {
144153
AsyncRequestBody.fromBytes(bytes));
145154
};
146155

147-
StabilityTestRunner.newRunner()
156+
StabilityTestRunner.newRunner(allowedPeakThreads)
148157
.testName("S3AsyncStabilityTest.putObject")
149158
.futureFactory(future)
150159
.requestCountPerRun(CONCURRENCY)
@@ -160,7 +169,7 @@ protected void getObject() {
160169
return testClient.getObject(b -> b.bucket(getTestBucketName()).key(keyName), AsyncResponseTransformer.toFile(path));
161170
};
162171

163-
StabilityTestRunner.newRunner()
172+
StabilityTestRunner.newRunner(allowedPeakThreads)
164173
.testName("S3AsyncStabilityTest.getObject")
165174
.futureFactory(future)
166175
.requestCountPerRun(CONCURRENCY)
@@ -183,7 +192,7 @@ protected static void deleteBucketAndAllContents(S3AsyncClient client, String bu
183192

184193
client.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build()).join();
185194
} catch (Exception e) {
186-
log.error(() -> "Failed to delete bucket: " +bucketName);
195+
log.error(() -> "Failed to delete bucket: " + bucketName, e);
187196
}
188197
}
189198

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/s3/S3MultipartJavaBasedStabilityTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
package software.amazon.awssdk.stability.tests.s3;
1717

18+
import java.time.Duration;
1819
import org.junit.jupiter.api.AfterAll;
1920
import org.junit.jupiter.api.BeforeAll;
21+
import software.amazon.awssdk.core.retry.RetryPolicy;
2022
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
2123
import software.amazon.awssdk.services.s3.S3AsyncClient;
2224

@@ -27,24 +29,31 @@ public class S3MultipartJavaBasedStabilityTest extends S3AsyncBaseStabilityTest
2729
static {
2830
multipartJavaBasedClient = S3AsyncClient.builder()
2931
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
32+
.httpClientBuilder(NettyNioAsyncHttpClient.builder()
33+
.maxConcurrency(CONCURRENCY))
3034
.multipartEnabled(true)
35+
.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMinutes(5))
36+
// Retry at test level
37+
.retryPolicy(RetryPolicy.none()))
3138
.build();
3239
}
3340

3441
public S3MultipartJavaBasedStabilityTest() {
35-
super(multipartJavaBasedClient);
42+
// S3 multipart client uses more threads because for large file uploads, it reads from different positions of the files
43+
// at the same time, which will trigger more Java I/O threads to spin up
44+
super(multipartJavaBasedClient, 250);
3645
}
3746

3847
@BeforeAll
3948
public static void setup() {
40-
s3ApacheClient.createBucket(b -> b.bucket(BUCKET_NAME));
49+
multipartJavaBasedClient.createBucket(b -> b.bucket(BUCKET_NAME)).join();
50+
multipartJavaBasedClient.waiter().waitUntilBucketExists(b -> b.bucket(BUCKET_NAME)).join();
4151
}
4252

4353
@AfterAll
4454
public static void cleanup() {
4555
deleteBucketAndAllContents(multipartJavaBasedClient, BUCKET_NAME);
4656
multipartJavaBasedClient.close();
47-
s3ApacheClient.close();
4857
}
4958

5059
@Override

test/stability-tests/src/it/java/software/amazon/awssdk/stability/tests/utils/StabilityTestRunner.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@
6969
*/
7070
public class StabilityTestRunner {
7171

72+
public static final int ALLOWED_MAX_PEAK_THREAD_COUNT = 90;
7273
private static final Logger log = Logger.loggerFor(StabilityTestRunner.class);
7374
private static final double ALLOWED_FAILURE_RATIO = 0.05;
7475
private static final int TESTS_TIMEOUT_IN_MINUTES = 60;
7576
// The peak thread count might be different depending on the machine the tests are currently running on.
7677
// because of the internal thread pool used in AsynchronousFileChannel
7778
// Also, synchronous clients have their own thread pools so this measurement needs to be mutable
7879
// so that the async and synchronous paths can both use this runner.
79-
private int allowedPeakThreadCount = 150;
80+
private int allowedPeakThreadCount = ALLOWED_MAX_PEAK_THREAD_COUNT;;
8081

8182
private ThreadMXBean threadMXBean;
8283
private IntFunction<CompletableFuture<?>> futureFactory;
@@ -343,12 +344,12 @@ private void processResult(TestResult testResult) {
343344
}
344345

345346
if (testResult.peakThreadCount() > allowedPeakThreadCount) {
346-
String errorMessage = String.format("The number of peak thread exceeds the allowed peakThread threshold %s",
347-
allowedPeakThreadCount);
347+
String errorMessage = String.format("The number of peak thread %s exceeds the allowed peakThread threshold %s",
348+
testResult.peakThreadCount(), allowedPeakThreadCount);
348349

349350

350351
threadDump(testResult.testName());
351-
throw new AssertionError(errorMessage);
352+
log.warn(() -> errorMessage);
352353
}
353354
}
354355

0 commit comments

Comments
 (0)