Skip to content

chore: increase awaitTermination timeout in ITBulkConnectionTest#4375

Open
sakthivelmanii wants to merge 3 commits intomainfrom
fix/directpath-failures-in-presubmit
Open

chore: increase awaitTermination timeout in ITBulkConnectionTest#4375
sakthivelmanii wants to merge 3 commits intomainfrom
fix/directpath-failures-in-presubmit

Conversation

@sakthivelmanii
Copy link
Collaborator

This PR fixes an intermittent failure in ITBulkConnectionTest caused by the test threads not finishing completely before the test concludes.

The testBulkCreateConnectionsMultiThreaded test shuts down the thread pool and then waits for the threads to finish using awaitTermination(10L, TimeUnit.SECONDS). Under load, or in constrained environments, 10 seconds is sometimes insufficient for 250 connections to be opened, queried, and closed across 50 background threads. If the wait times out, the test proceeds to call closeSpanner(), which checks the connection pool. Because some of the original threads are still running and haven't called close() on their connections yet, closeSpanner() throws a FAILED_PRECONDITION: There is/are X connection(s) still open exception.

This PR increases the awaitTermination timeout to 60 seconds and adds an assertion constraint to prevent the test from falling through.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes test failure ☕️

If you write sample code, please follow the samples format.

@sakthivelmanii sakthivelmanii requested review from a team as code owners March 4, 2026 11:42
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: spanner Issues related to the googleapis/java-spanner API. labels Mar 4, 2026
@sakthivelmanii sakthivelmanii force-pushed the fix/directpath-failures-in-presubmit branch from 70dbc58 to 5eb9228 Compare March 4, 2026 11:43
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an intermittent test failure in ITBulkConnectionTest where the testBulkCreateConnectionsMultiThreaded method would occasionally fail due to an insufficient awaitTermination period for its thread pool. The previous 10-second timeout was not always enough for 250 connections to be processed across 50 threads, leading to FAILED_PRECONDITION exceptions. By extending the timeout to 60 seconds and adding an explicit assertion for successful termination, the test's stability and reliability are significantly improved.

Highlights

  • Increased awaitTermination Timeout: The awaitTermination timeout in ITBulkConnectionTest.java has been increased from 10 seconds to 60 seconds to prevent intermittent test failures caused by threads not finishing in time under load.
  • Added Assertion for Termination: An assertThat assertion was added to verify that the executor.awaitTermination call successfully returns true, ensuring the thread pool terminates as expected within the new timeout period.
Changelog
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/it/ITBulkConnectionTest.java
    • Increased the awaitTermination timeout from 10 seconds to 60 seconds.
    • Added an assertThat assertion to confirm successful thread pool termination.
Activity
  • The author identified an intermittent test failure related to thread pool termination.
  • The author implemented a fix by adjusting a timeout value and adding a verification assertion.
  • The author confirmed that all pre-submission checks, including opening an issue, passing tests/linter, and maintaining code coverage, were completed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sakthivelmanii sakthivelmanii changed the title fix: increase awaitTermination timeout in ITBulkConnectionTest chore: increase awaitTermination timeout in ITBulkConnectionTest Mar 4, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an intermittent test failure in ITBulkConnectionTest by increasing the awaitTermination timeout and adding an assertion to ensure the executor terminates successfully. The change is correct and improves the test's reliability. I have one suggestion to improve maintainability by extracting the new timeout value into a constant.

}
executor.shutdown();
executor.awaitTermination(10L, TimeUnit.SECONDS);
assertThat(executor.awaitTermination(60L, TimeUnit.SECONDS), is(true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and maintainability, it would be best to extract the magic number 60L into a named constant at the class level. This makes the purpose of the value clear and simplifies future modifications.

For example:

private static final long AWAIT_TERMINATION_TIMEOUT_SECONDS = 60L;

And then use it in the assertion:

assertThat(executor.awaitTermination(AWAIT_TERMINATION_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));

@sakthivelmanii sakthivelmanii added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: xs Pull request size is extra small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants