Close streaming after loop completion#5201
Close streaming after loop completion#5201priyaranjannanda wants to merge 1 commit intoopenconfig:mainfrom
Conversation
priyaranjannanda
commented
Mar 6, 2026
- Changes to Close streaming after loop completion
Summary of ChangesHello, 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 refactors the stream management within the Highlights
Changelog
Activity
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 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 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
|
There was a problem hiding this comment.
Code Review
The pull request correctly addresses a resource leak by ensuring that gNMI sample streams are closed after use. The change removes incorrect defer statements and adds an explicit cleanup loop. My review includes a suggestion to refactor the test to use t.Run for subtests. This would align with the repository's style guide and allow for more idiomatic resource management using defer.
| //Close the connections: | ||
| for portName := range ochs { | ||
| ochStreams[portName].Close() | ||
| trStreams[portName].Close() | ||
| interfaceStreams[portName].Close() | ||
| } |
There was a problem hiding this comment.
While this explicit loop correctly closes the streams, the test structure could be improved by using t.Run for subtests. This is recommended by the repository style guide to improve test output clarity.
Using t.Run would create a new scope for each test case (each combination of frequency and power), allowing you to use defer for resource management. This is generally safer and leads to cleaner code.
Example structure:
for _, frequency := range frequencies {
for _, targetOpticalPower := range targetOpticalPowers {
t.Run(fmt.Sprintf("freq_%d_power_%.1f", frequency, targetOpticalPower), func(t *testing.T) {
// Create streams here
// ...
// Use defer to close streams, which will be executed at the end of this subtest.
defer stream.Close()
// ... rest of the test logic for this case ...
})
}
}This refactoring would make the test more idiomatic, easier to debug, and fully compliant with the style guide.
References
- The style guide recommends using
t.Runfor subtests to ensure clear output for passed/failed steps. The current test iterates through parameter combinations without creating subtests. (link)