Skip to content

Commit 112b307

Browse files
authored
fix: flaky test testAsyncRefreshHandlesFailures (#1342)
1 parent 48c6e2c commit 112b307

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

services/s3/common/test/aws/sdk/kotlin/services/s3/express/DefaultS3ExpressCredentialsProviderTest.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ class DefaultS3ExpressCredentialsProviderTest {
161161

162162
// Entry expires in 30 seconds, refresh buffer is 1 minute. Next `resolve` call should trigger the async refresh
163163
val cache = S3ExpressCredentialsCache()
164-
val successEntry = getCacheEntry(timeSource.markNow() + 30.seconds, bucket = "SuccessfulBucket", bootstrapCredentials = Credentials("1", "1", "1"))
165-
val failedEntry = getCacheEntry(timeSource.markNow() + 30.seconds, bucket = "ExceptionBucket", bootstrapCredentials = Credentials("1", "1", "1"))
164+
val successEntry = getCacheEntry(timeSource.markNow() + 30.seconds, bucket = "SuccessfulBucket")
165+
val failedEntry = getCacheEntry(timeSource.markNow() + 30.seconds, bucket = "ExceptionBucket")
166166
cache.put(successEntry.key, successEntry.value)
167167
cache.put(failedEntry.key, failedEntry.value)
168168

@@ -173,9 +173,8 @@ class DefaultS3ExpressCredentialsProviderTest {
173173
expiration = clock.now() + 5.minutes
174174
}
175175

176-
// client will throw an exception when `ExceptionBucket` credentials are fetched,
177-
// but there should be no crash
178-
val testClient = TestS3Client(expectedCredentials, throwExceptionOnBucketNamed = "ExceptionBucket", baseCredentials = Credentials("1", "1", "1"))
176+
// client should throw an exception when `ExceptionBucket` credentials are fetched, but it should be caught
177+
val testClient = TestS3Client(expectedCredentials, throwExceptionOnBucketNamed = "ExceptionBucket")
179178

180179
val provider = DefaultS3ExpressCredentialsProvider(timeSource, clock, cache, refreshBuffer = 1.minutes)
181180
val attributes = ExecutionContext.build {
@@ -184,11 +183,21 @@ class DefaultS3ExpressCredentialsProviderTest {
184183
}
185184
provider.resolve(attributes)
186185

186+
withTimeout(5.seconds) {
187+
while (testClient.numCreateSession != 1) {
188+
yield()
189+
}
190+
}
191+
assertEquals(1, testClient.numCreateSession)
192+
187193
attributes[S3Attributes.Bucket] = "SuccessfulBucket"
188194
provider.resolve(attributes)
189195

190-
// allow the async refresh to initiate before closing the provider
191-
runBlocking { delay(500.milliseconds) }
196+
withTimeout(5.seconds) {
197+
while (testClient.numCreateSession != 2) {
198+
yield()
199+
}
200+
}
192201

193202
provider.close()
194203
provider.coroutineContext.job.join()

0 commit comments

Comments
 (0)