Skip to content

Conversation

briandorsey
Copy link
Member

Description

TestCreateSubscriptionWithSMT has been failing in repo-wide builds with a nil topic error.

  • update getOrCreateTopic test function to avoid race between checking topic existence and creating the topic. (tests are using t.Parallel(), so it can happen across tests)
  • in TestCreateSubscriptionWithSMT:
    • use shared getOrCreateTopic rather than local code. (local code had a bug which only occured when topic didn't already exist.)
    • use test specific topicID
    • use only one Retry block in body of the test so new topic both lives long enough to run the test and is cleaned up by defer.

Helps fix tests failing in Renovate PR #5225

Checklist

TestCreateSubscriptionWithSMT has been failing in repo-wide builds with a nil topic error. 

* update getOrCreateTopic test function to avoid race between checking topic existence and creating the topic. (tests are using t.Parallel(), so it can happen across tests)
* in TestCreateSubscriptionWithSMT:
  * use shared getOrCreateTopic rather than local code. (local code had a bug which only occured when topic didn't already exist.)
  * use test specific topicID
  * use only one Retry block in body of the test so new topic both lives long enough to run the test and is cleaned up by defer.
@briandorsey briandorsey requested review from a team as code owners September 5, 2025 21:03
@product-auto-label product-auto-label bot added api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples. labels Sep 5, 2025
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.

Summary of Changes

Hello @briandorsey, 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 addresses a persistent test failure in TestCreateSubscriptionWithSMT by resolving a race condition in topic creation and refactoring the test's setup. The changes enhance the reliability and isolation of the test, ensuring consistent behavior across parallel executions and proper resource management.

Highlights

  • Race Condition Fix: The getOrCreateTopic helper function was updated to prevent a race condition that could occur when parallel tests checked for topic existence and then attempted to create it. The new logic attempts to create the topic first and handles AlreadyExists errors.
  • Test Refactor: The TestCreateSubscriptionWithSMT function was refactored to utilize the shared and improved getOrCreateTopic helper, replacing its previous local topic creation logic which had a bug.
  • Test Isolation: A test-specific topic ID is now used within TestCreateSubscriptionWithSMT to ensure better isolation and prevent conflicts with other tests.
  • Test Reliability: The TestCreateSubscriptionWithSMT now uses a single Retry block, ensuring the topic lives long enough for the test to complete and is properly cleaned up via defer.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 effectively resolves a race condition in the getOrCreateTopic test helper by adopting an 'act-then-check' strategy. It also rectifies a failing test, TestCreateSubscriptionWithSMT, by utilizing this improved helper, employing a test-specific topic ID, and ensuring proper resource cleanup. The changes are well-reasoned and correctly address the reported issues. My review includes a suggestion to enhance error message formatting for improved debuggability in the test helper.

@briandorsey briandorsey merged commit 2a91361 into main Sep 5, 2025
12 checks passed
@briandorsey briandorsey deleted the briandorsey-mlppqknltvnk branch September 5, 2025 21:46
@briandorsey briandorsey self-assigned this Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants