Repository navigation
test(spanner): unflake ITBulkConnectionTest.testBulkCreateConnectionsMultiThreaded - #14604
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the multi-threaded bulk connection creation test in ITBulkConnectionTest.java to track the submitted tasks using Future objects. It now asserts that the executor terminates successfully within 60 seconds and verifies that each task completed without throwing an exception. There are no review comments, so I have no feedback to provide.
sakthivelmanii
force-pushed
the
unflake-b571072226-pro
branch
3 times, most recently
from
October 8, 2026 14:52
bd97433 to
e901fcf
Compare
sakthivelmanii
force-pushed
the
unflake-b571072226-pro
branch
from
October 8, 2026 15:49
e901fcf to
f330820
Compare
sakthivelmanii
enabled auto-merge (squash)
October 8, 2026 16:21
olavloite
approved these changes
Oct 8, 2026
| @Test | ||
| public void testBulkCreateConnectionsMultiThreaded() throws InterruptedException { | ||
| public void testBulkCreateConnectionsMultiThreaded() throws Exception { | ||
| ExecutorService executor = Executors.newFixedThreadPool(50); |
Contributor
There was a problem hiding this comment.
nit: can we add a try-finally block to ensure that the executor is shut down also when the test fails, like this (and also use JUnit style assertions):
@Test
public void testBulkCreateConnectionsMultiThreaded() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(50);
try {
List<Future<?>> futures = new ArrayList<>(NUMBER_OF_TEST_CONNECTIONS);
for (int i = 0; i < NUMBER_OF_TEST_CONNECTIONS; i++) {
futures.add(
executor.submit(
() -> {
try (ITConnection connection = createConnection()) {
try (ResultSet resultSet = connection.executeQuery(Statement.of("select 1"))) {
assertTrue(resultSet.next());
assertNotNull(connection.getReadTimestamp());
}
}
return null;
}));
}
executor.shutdown();
assertTrue(
"Executor did not terminate within timeout; active threads remain",
executor.awaitTermination(60L, TimeUnit.SECONDS));
for (Future<?> future : futures) {
assertNull(future.get());
}
} finally {
if (!executor.isTerminated()) {
executor.shutdownNow();
executor.awaitTermination(5L, TimeUnit.SECONDS);
}
}
closeSpanner();
}
sakthivelmanii
added a commit
that referenced
this pull request
Oct 8, 2026
…MultiThreaded (#14610) ### Summary Follow-up to #14604 to address review feedback on `ITBulkConnectionTest.testBulkCreateConnectionsMultiThreaded`: - Wrap the `ExecutorService` execution in a `try-finally` block calling `executor.shutdownNow()` and `executor.awaitTermination(5L, TimeUnit.SECONDS)` if the executor has not terminated when the test exits. - Include a descriptive failure message in `assertTrue(..., executor.awaitTermination(60L, TimeUnit.SECONDS))` and use JUnit `assertTrue` / `assertNotNull` assertions inside the worker task.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
ITBulkConnectionTest.testBulkCreateConnectionsMultiThreadedsubmits 250 connection and query tasks across a 50-thread pool and callsexecutor.awaitTermination(10L, TimeUnit.SECONDS)without asserting its return value or waiting for the submitted taskFutures. When initial Spanner client and metrics setup plus 250 connection handshakes exceed 10 seconds,awaitTerminationreturnsfalsewhile worker threads still have open connections in flight, causingcloseSpanner()in@AfterClassto fail withFAILED_PRECONDITION: There is/are 1 connection(s) still open. Close all connections before calling closeSpanner().Fix
Futures and assertassertNull(future.get())to propagate any worker exception and ensure all connections are closed before test completion.executor.awaitTerminationtimeout from 10 seconds to 60 seconds and assertassertTrue(executor.awaitTermination(60L, TimeUnit.SECONDS)).