Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 6104b06

Browse files
Update logic of test
1 parent 539cffc commit 6104b06

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ public void testDeadlineExceededErrorWithOneRetryWithParallelRequests()
344344

345345
// First set of request should fail with an error
346346
CountDownLatch failureCountDownLatch = new CountDownLatch(3);
347+
CountDownLatch executionCountLatch = new CountDownLatch(3);
348+
mockSpanner.freeze();
347349
for (int i = 0; i < 3; i++) {
348-
if (i == 0) {
349-
mockSpanner.freeze();
350-
}
351350
executor.submit(
352351
() -> {
352+
executionCountLatch.countDown();
353353
try {
354354
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
355355
//noinspection StatementWithEmptyBody
@@ -361,11 +361,10 @@ public void testDeadlineExceededErrorWithOneRetryWithParallelRequests()
361361
failureCountDownLatch.countDown();
362362
}
363363
});
364-
if (i == 2) {
365-
Thread.sleep(1000);
366-
mockSpanner.unfreeze();
367-
}
368364
}
365+
assertTrue(executionCountLatch.await(2, TimeUnit.SECONDS));
366+
Thread.sleep(1000);
367+
mockSpanner.unfreeze();
369368

370369
System.out.println(
371370
"---------------------------------------------------------------------------END");
@@ -374,13 +373,14 @@ public void testDeadlineExceededErrorWithOneRetryWithParallelRequests()
374373

375374
// Second set of requests should pass
376375
CountDownLatch countDownLatch = new CountDownLatch(3);
376+
CountDownLatch successExecutionCountLatch = new CountDownLatch(3);
377+
378+
mockSpanner.freeze();
377379
for (int i = 0; i < 3; i++) {
378-
if (i == 0) {
379-
mockSpanner.freeze();
380-
}
381380
executor.submit(
382381
() -> {
383382
try {
383+
successExecutionCountLatch.countDown();
384384
try (ResultSet resultSet = client.singleUse().executeQuery(STATEMENT)) {
385385
//noinspection StatementWithEmptyBody
386386
while (resultSet.next()) {
@@ -391,11 +391,10 @@ public void testDeadlineExceededErrorWithOneRetryWithParallelRequests()
391391
countDownLatch.countDown();
392392
}
393393
});
394-
if (i == 2) {
395-
Thread.sleep(1000);
396-
mockSpanner.unfreeze();
397-
}
398394
}
395+
assertTrue(successExecutionCountLatch.await(2, TimeUnit.SECONDS));
396+
Thread.sleep(1000);
397+
mockSpanner.unfreeze();
399398

400399
countDownLatch.await(2, TimeUnit.SECONDS);
401400
assertEquals(3, countDownLatch.getCount());

0 commit comments

Comments
 (0)