-
Notifications
You must be signed in to change notification settings - Fork 292
cdc: fix data race in TestGCAndCleanup by moving global variable modification to TestMain #12372
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: release-6.5
Are you sure you want to change the base?
cdc: fix data race in TestGCAndCleanup by moving global variable modification to TestMain #12372
Conversation
…fication to TestMain
|
This cherry pick PR is for a release branch and has not yet been approved by triage owners. To merge this cherry pick:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Summary of ChangesHello @wlwilliamx, 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 a data race issue identified in the Highlights
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 correctly fixes a data race in TestGCAndCleanup by moving the modification of a global variable to the TestMain function. This is the standard and correct way to handle package-level test setup, ensuring that the global state is modified only once before any parallel tests are run. The change is effective and well-implemented. I have one minor suggestion to improve code readability.
|
|
||
| func TestMain(m *testing.M) { | ||
| originValue := redo.DefaultGCIntervalInMs | ||
| redo.DefaultGCIntervalInMs = 20 |
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.
The value 20 is a magic number. To improve readability and maintainability, it's better to define it as a named constant. This makes the purpose of the value clearer, especially since it's used to configure a test-specific behavior for the whole package.
const testDefaultGCIntervalInMs = 20
redo.DefaultGCIntervalInMs = testDefaultGCIntervalInMs|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lidezhu, wk989898 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What problem does this PR solve?
Issue Number: close #12371
What is changed and how it works?
This PR fixes a data race detected in the
cdc/redotest suite.Changes:
cdc/redo/meta_manager_test.go:TestGCAndCleanupthat setsredo.DefaultGCIntervalInMsto20and defers its reset. This stops the global variable from being written to inside a parallel test.cdc/redo/main_test.go:github.com/pingcap/tiflow/pkg/redoimport.redo.DefaultGCIntervalInMs = 20into theTestMainfunction.deferstatement is used inTestMainto restore the original value after all tests in thecdc/redopackage have finished running.By moving this logic to
TestMain, the global variable is set once at the beginning of the entire package's test run, before any parallel tests are executed. This provides a stable test environment for all tests in the package while completely eliminating the data race.Check List
Tests
Questions
Will it cause performance regression or break compatibility?
None
Do you need to update user documentation, design documentation or monitoring documentation?
None
Release note