-
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
maybe common mistakes with table driven tests and t.Parallel() #27779
Comments
@tisonkun please take a look and confirm, thanks |
I think you can add the linter and trying to generate a report on how much we suffer from this problem. For the PR #27557 , just fix it and move forward. |
above is paralleltest run result, it checks several cases:
i will only pay attention to the third one and try fix them, about 14 occurrences |
more detail here: https://golang.org/doc/faq#closures_and_goroutines |
Write |
Bug Report
I am tring to figure out a strang problem in pr #27557, in which 2 tests fail if i add
t.Parallel()
and work well if i removed it. Then when i tried to find more info aboutt.Parallel()
, i found that there maybe an common mistake in our test.problem
for above table driven tests,
test1
,test2
,test3
should fail,test 4
should pass, it works as expect.but if we add
t.Parallel()
by uncomment the line, 4 test will pass, and the output is:reason
the reason is explained well in Go common mistakes guide, 2 reason:
how to resolve
for i := 0; i < 3; i++ { + i := i // Copy i into a new variable. out = append(out, &i) }
also, we may add linter to avoid such pitfall https://github.com/kunwardeep/paralleltest
todo
i seached repo, there already some wrong occurance there, such as
request_builder_test.go
,table/column_test.go
,i am not sure how many contributors are awared of this, the occurances ge merged means even some experienced reviewer may not aware of it.
so i submit a issue here, we need fix them and pay attention to this scenario, and may also add notice to https://pingcap.github.io/tidb-dev-guide/get-started/write-and-run-unit-tests.html
The text was updated successfully, but these errors were encountered: