Skip to content

Commit 5567072

Browse files
Fix GCS Test testReadLargeBlobWithRetries (#52619)
The countdown didn't work well here because it only returns `true` once the countdown reaches `0` but can on subsequent executions return `false` again if a countdown at `0` is counted down again, leading to more than the expected number of simulated failures. Closes #52607
1 parent 2c6aa90 commit 5567072

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void testReadBlobWithRetries() throws Exception {
202202

203203
public void testReadLargeBlobWithRetries() throws Exception {
204204
final int maxRetries = randomIntBetween(2, 10);
205-
final CountDown countDown = new CountDown(maxRetries);
205+
final AtomicInteger countDown = new AtomicInteger(maxRetries);
206206

207207
// SDK reads in 2 MB chunks so we use twice that to simulate 2 chunks
208208
final byte[] bytes = randomBytes(1 << 22);
@@ -214,7 +214,7 @@ public void testReadLargeBlobWithRetries() throws Exception {
214214
final int end = Integer.parseInt(range[1]);
215215
final byte[] chunk = Arrays.copyOfRange(bytes, offset, Math.min(end + 1, bytes.length));
216216
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), chunk.length);
217-
if (randomBoolean() && countDown.countDown() == false) {
217+
if (randomBoolean() && countDown.decrementAndGet() >= 0) {
218218
exchange.getResponseBody().write(chunk, 0, chunk.length - 1);
219219
exchange.close();
220220
return;

0 commit comments

Comments
 (0)