dataconnect(test): fix resource leaks in DataConnectGrpcRPCsUnitTest.kt#8359
Conversation
Using Gemini Code AssistThe 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
Customization To customize the 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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. |
|
/gemini review |
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new Cleanups utility class to manage synchronous and suspending test cleanup actions, replacing the JUnit CleanupsRule in DataConnectGrpcRPCsUnitTest.kt. It also adds corresponding unit tests for Cleanups and improves the shutdown behavior of the in-process gRPC streaming server. Feedback was provided to replace autoCloseable::class.qualifiedName with autoCloseable.javaClass.name to avoid potential reflection overhead and nullability issues.
This PR addresses resource leak issues in
DataConnectGrpcRPCsUnitTestby introducing a thread-safeCleanupsutility class to manage and guarantee the teardown of resources in reverse order of their registration. It refactors the unit tests to utilizeCleanups, ensuring proper cleanup of servers, caches, and gRPC RPC clients.Highlights
DataConnectGrpcRPCsUnitTestto run withCleanups().use { ... }, registering all server, cache, and client instances for guaranteed teardown, resolving resource leaks.CleanupsUtility: Introduced a thread-safeCleanupsutility class implementingAutoCloseablethat registers synchronous and suspending cleanup tasks, executing them in reverse-registration order, aggregating any thrown exceptions.InProcessDataConnectGrpcStreamingServerto cleanly await termination during its shutdown process.Changelog
Changelog
Cleanupsutility for managing temporary resources (caching, gRPC clients, servers) and cancel pending background jobs during teardown.InProcessDataConnectGrpcStreamingServer.close()to useshutdownNow()and await termination of the gRPC server.Cleanupsutility class to register and execute synchronous and suspending cleanup functions onclose().addSuppressed()when multiple cleanups fail.Cleanupsclass, verifying registration, ordering, exception handling, and double-close behavior.