-
Notifications
You must be signed in to change notification settings - Fork 5k
fix:add check transcation after new db #34175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ansactions after database creation
Summary of ChangesHello @tomchon, 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 enhances the test framework by introducing a robust mechanism to verify that all database transactions are cleared following the creation of a new database. This is achieved through a new utility function that actively waits for transaction completion, which is then integrated into the database creation process. Additionally, a relevant test case has been activated in the CI pipeline to leverage this new functionality. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
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 aims to fix a race condition by waiting for transactions to complete after creating a database. The approach is sound, but there are a couple of areas for improvement.
The new waitTransactionZeroWithTsql method should be made more robust by explicitly handling timeouts to prevent silent test failures. I've provided a suggestion to improve its implementation.
More critically, the new test case enabled in this PR (test_tmq_snapshot_basic.py) does not actually use the new fix. It calls tdCom.create_database instead of tmqCom.create_database, so the waiting logic is never executed for this test. This needs to be corrected to ensure the fix is effective and properly tested.
Lastly, there's a small typo in the pull request title ('transcation' should be 'transaction').
| def waitTransactionZeroWithTsql(self, tsql): | ||
| for i in range(300): | ||
| sql ="show transactions;" | ||
| tsql.execute(sql) | ||
| result = tsql.fetchall() | ||
| rows = len(result) | ||
| if rows == 0: | ||
| tdLog.info("transaction count became zero.") | ||
| return True | ||
| time.sleep(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new method can be improved for clarity, robustness, and configurability:
- Timeout Handling: The current implementation implicitly returns
Noneif the loop completes, which could lead to silent failures in tests. It's better to explicitly handle the timeout, for instance by callingtdLog.exit()which seems to be the standard way to fail tests in this project. - Readability: The loop variable
iis unused and can be replaced with_. The check for an empty result can be made more Pythonic (if not result:). Also, the spacing insql ="show transactions;"is unconventional. - Configurability: The timeout duration is hardcoded. Making it a parameter with a default value would be more flexible.
Here is a suggested refactoring that addresses these points:
| def waitTransactionZeroWithTsql(self, tsql): | |
| for i in range(300): | |
| sql ="show transactions;" | |
| tsql.execute(sql) | |
| result = tsql.fetchall() | |
| rows = len(result) | |
| if rows == 0: | |
| tdLog.info("transaction count became zero.") | |
| return True | |
| time.sleep(1) | |
| def waitTransactionZeroWithTsql(self, tsql, timeout=300): | |
| for _ in range(timeout): | |
| sql = "show transactions;" | |
| tsql.execute(sql) | |
| result = tsql.fetchall() | |
| if not result: | |
| tdLog.info("transaction count became zero.") | |
| return True | |
| time.sleep(1) | |
| tdLog.exit(f"Timeout after {timeout} seconds waiting for transaction count to become zero.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a transaction monitoring mechanism to ensure transactions complete before proceeding after database creation. The title contains a spelling error: "transcation" should be "transaction".
Key Changes:
- Introduces
waitTransactionZeroWithTsqlmethod to poll for zero active transactions - Integrates the transaction check into the
create_databasemethod - Enables a previously commented-out test case for TMQ snapshot functionality
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/new_test_framework/utils/tmqUtil.py | Adds transaction wait utility method and integrates it into database creation to ensure clean state |
| test/ci/win_cases.task | Uncomments and updates test case from tmqConsFromTsdb to test_tmq_snapshot_basic.py |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def waitTransactionZeroWithTsql(self, tsql): | ||
| for i in range(300): | ||
| sql ="show transactions;" |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the assignment operator. The line should be formatted as 'sql = "show transactions;"' with a space after the equals sign to maintain consistent code style throughout the file.
| sql ="show transactions;" | |
| sql = "show transactions;" |
…out and improve transaction checking logic
…use td_sql and improve error handling
…or transaction checking
…ction checking function name
…eadability and consistency
…es within a timeout
https://project.feishu.cn/taosdata_td/defect/detail/6467995692