-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: run tests with race checks #25870
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: master
Are you sure you want to change the base?
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.
Hey there - I've reviewed your changes - here's some feedback:
- The race detector requires cgo, so
CGO_ENABLED=0will prevent-racefrom working; consider either removingCGO_ENABLED=0for this target or providing a separate race-enabled test target. - Running all tests with
-raceby default can significantly slow down the test suite; you might want to add a separatetest-racemake target instead of changing the defaulttesttarget.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The race detector requires cgo, so `CGO_ENABLED=0` will prevent `-race` from working; consider either removing `CGO_ENABLED=0` for this target or providing a separate race-enabled test target.
- Running all tests with `-race` by default can significantly slow down the test suite; you might want to add a separate `test-race` make target instead of changing the default `test` target.
## Individual Comments
### Comment 1
<location> `Makefile:83` </location>
<code_context>
test::
@echo "Running testsuite"
- CGO_ENABLED=0 go test $(BUILD_TAGS) ./...
+ CGO_ENABLED=0 go test -race $(BUILD_TAGS) ./...
porcelain::
</code_context>
<issue_to_address>
**issue (testing):** Race detector is effectively disabled when CGO is turned off.
Because the Go race detector depends on cgo, `-race` is ignored when `CGO_ENABLED=0`. If you want these tests to run with race detection, you’ll need to run them with `CGO_ENABLED=1` (e.g. via a separate `test-race` target) so the flag actually takes effect.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
...only this won't work on all plattforms that we're supporting :/ |
Better on some than on none, right? I would guess Linux is the primary target platform |
9fc54cc to
bc03751
Compare
| @OS=$$(go env GOOS); \ | ||
| if [ "$$OS" = "linux" ] || [ "$$OS" = "darwin" ]; then \ | ||
| echo "Running tests on $$OS"; \ | ||
| CGO_ENABLED=1 go test -race $(BUILD_TAGS) ./...; \ |
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.
| CGO_ENABLED=1 go test -race $(BUILD_TAGS) ./...; \ | |
| CGO_ENABLED=0 go test -race $(BUILD_TAGS) ./...; \ |
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.
Sadly, this is required - #25870 (comment)
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.
Because the bot says so? I can test, that's for sure.
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.
CGO_ENABLED=0 got -race . -timeout 5s -run TestRace
==================
WARNING: DATA RACE
Read at 0x00c000674a58 by goroutine 31:
github.com/evcc-io/evcc.TestRace.func2()
/Users/a25058/htdocs/evcc/race_test.go:16 +0x2c
Previous write at 0x00c000674a58 by goroutine 30:
github.com/evcc-io/evcc.TestRace.func1()
/Users/a25058/htdocs/evcc/race_test.go:10 +0x3c
Goroutine 31 (running) created at:
github.com/evcc-io/evcc.TestRace()
/Users/a25058/htdocs/evcc/race_test.go:14 +0xf8
testing.tRunner()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1934 +0x164
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1997 +0x3c
Goroutine 30 (running) created at:
github.com/evcc-io/evcc.TestRace()
/Users/a25058/htdocs/evcc/race_test.go:8 +0x98
testing.tRunner()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1934 +0x164
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1997 +0x3c
==================
==================
WARNING: DATA RACE
Write at 0x00c000674a58 by goroutine 31:
github.com/evcc-io/evcc.TestRace.func2()
/Users/a25058/htdocs/evcc/race_test.go:16 +0x3c
Previous write at 0x00c000674a58 by goroutine 30:
github.com/evcc-io/evcc.TestRace.func1()
/Users/a25058/htdocs/evcc/race_test.go:10 +0x3c
Goroutine 31 (running) created at:
github.com/evcc-io/evcc.TestRace()
/Users/a25058/htdocs/evcc/race_test.go:14 +0xf8
testing.tRunner()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1934 +0x164
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1997 +0x3c
Goroutine 30 (running) created at:
github.com/evcc-io/evcc.TestRace()
/Users/a25058/htdocs/evcc/race_test.go:8 +0x98
testing.tRunner()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1934 +0x164
testing.(*T).Run.gowrap1()
/opt/homebrew/Cellar/go/1.25.5/libexec/src/testing/testing.go:1997 +0x3c
==================
FAIL
FAIL github.com/evcc-io/evcc 1.352s
FAIL
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.
package main
import "testing"
func TestRace(t *testing.T) {
var i int
go func() {
for {
i += 1
}
}()
go func() {
for {
i -= 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.
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.
Yeah we can use a different race detector (in the issue thread) or leave as-is.
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.
Shall we split the cases once more? No CGO would be preferred since it may not always build when you pull in the wrong dependency...
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.
I mean split osx and linux?
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.
Sure, we can split this further
|
We can only merge this when issues are fixed. Amongst them lorenzodonini/ocpp-go#309 |
Yep, Ill try to find some time to get this resolved |
|
Bzw, great PRs- did you already join us on Slack? |
Thanks! I just did 😃 |
bc03751 to
6b5fd03
Compare
Since there is a lot of concurrent code with mutexes, channels etc, it would make sense that tests run with
-racecheck.