-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: modify GetGlobalConfig() to provide a thread safe API for unit test #17954
Conversation
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.
LGTM
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.
LGTM
@@ -139,13 +139,17 @@ func (tk *TestKit) GetConnectionID() { | |||
|
|||
// Exec executes a sql statement. | |||
func (tk *TestKit) Exec(sql string, args ...interface{}) (sqlexec.RecordSet, error) { | |||
return tk.ExecWithCtx(context.Background(), sql, args) |
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.
return tk.ExecWithCtx(context.Background(), sql, args) | |
return tk.ExecWithCtx(context.Background(), sql, args...) |
This change has performance cost, we have to lookup for the context every time we need the global config. This PR fix the race problem in another way #17964 |
I think this PR provides a test-local config mechanism, which allows a few tests in |
@tangenta Making an isolated env to run test requires much more effort. |
#17964 tried another way to fix DATA RACE |
What problem does this PR solve?
Problem Summary:
There is only one instance of global config, providing that many test cases run concurrently,
when an unit test modify the global config, it is easy to DATA RACE.
We have been struggle with this problem, in this commit I modify the
GetGlobalConfig
API to provide a thread safe mechanism for each test to use its own config.What is changed and how it works?
What's Changed:
GetGlobalConfig()
toGetGlobalConfig(ctx)
config.WithGlobalConfig()
functionHow it Works:
GetGlobalConfig will check the context first, if it find the
overrideConfigForTest
from the context, use that.Each test can use
MustExecWithCtx()
to override the global config for testing.Check List
Tests
Side effects
Modify exposed API break code compatibility
Release note