Skip to content

Commit f330820

Browse files
test(spanner): unflake ITBulkConnectionTest.testBulkCreateConnectionsMultiThreaded
1 parent 1d92aa5 commit f330820

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

‎java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITBulkConnectionTest.java‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import static org.hamcrest.CoreMatchers.is;
2020
import static org.hamcrest.CoreMatchers.notNullValue;
2121
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertTrue;
2224

2325
import com.google.cloud.spanner.ResultSet;
2426
import com.google.cloud.spanner.SerialIntegrationTest;
@@ -28,6 +30,7 @@
2830
import java.util.List;
2931
import java.util.concurrent.ExecutorService;
3032
import java.util.concurrent.Executors;
33+
import java.util.concurrent.Future;
3134
import java.util.concurrent.TimeUnit;
3235
import org.junit.Test;
3336
import org.junit.experimental.categories.Category;
@@ -65,22 +68,27 @@ public void testBulkCreateConnectionsSingleThreaded() {
6568
}
6669

6770
@Test
68-
public void testBulkCreateConnectionsMultiThreaded() throws InterruptedException {
71+
public void testBulkCreateConnectionsMultiThreaded() throws Exception {
6972
ExecutorService executor = Executors.newFixedThreadPool(50);
73+
List<Future<?>> futures = new ArrayList<>(NUMBER_OF_TEST_CONNECTIONS);
7074
for (int i = 0; i < NUMBER_OF_TEST_CONNECTIONS; i++) {
71-
executor.submit(
72-
() -> {
73-
try (ITConnection connection = createConnection()) {
74-
try (ResultSet rs = connection.executeQuery(Statement.of("select 1"))) {
75-
assertThat(rs.next(), is(true));
76-
assertThat(connection.getReadTimestamp(), is(notNullValue()));
77-
}
78-
}
79-
return null;
80-
});
75+
futures.add(
76+
executor.submit(
77+
() -> {
78+
try (ITConnection connection = createConnection()) {
79+
try (ResultSet rs = connection.executeQuery(Statement.of("select 1"))) {
80+
assertThat(rs.next(), is(true));
81+
assertThat(connection.getReadTimestamp(), is(notNullValue()));
82+
}
83+
}
84+
return null;
85+
}));
8186
}
8287
executor.shutdown();
83-
executor.awaitTermination(10L, TimeUnit.SECONDS);
88+
assertTrue(executor.awaitTermination(60L, TimeUnit.SECONDS));
89+
for (Future<?> future : futures) {
90+
assertNull(future.get());
91+
}
8492
// close Spanner instances explicitly. This method will throw an exception if there are any
8593
// connections still open in the pool
8694
closeSpanner();

0 commit comments

Comments
 (0)