Skip to content

Conversation

@xBlaz3kx
Copy link
Contributor

@xBlaz3kx xBlaz3kx commented Dec 7, 2025

Since there is a lot of concurrent code with mutexes, channels etc, it would make sense that tests run with -race check.

@andig andig added enhancement New feature or request infrastructure Basic functionality labels Dec 7, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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=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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@andig
Copy link
Member

andig commented Dec 7, 2025

Since there is a lot of code with mutexes, channels etc, it would make sense that tests run with -race check.

...only this won't work on all plattforms that we're supporting :/

@andig andig marked this pull request as draft December 7, 2025 12:36
@xBlaz3kx
Copy link
Contributor Author

xBlaz3kx commented Dec 7, 2025

Since there is a lot of code with mutexes, channels etc, it would make sense that tests run with -race check.

...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

@xBlaz3kx xBlaz3kx force-pushed the chore/test-with-race branch from 9fc54cc to bc03751 Compare December 7, 2025 13:40
@OS=$$(go env GOOS); \
if [ "$$OS" = "linux" ] || [ "$$OS" = "darwin" ]; then \
echo "Running tests on $$OS"; \
CGO_ENABLED=1 go test -race $(BUILD_TAGS) ./...; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CGO_ENABLED=1 go test -race $(BUILD_TAGS) ./...; \
CGO_ENABLED=0 go test -race $(BUILD_TAGS) ./...; \

Copy link
Contributor Author

@xBlaz3kx xBlaz3kx Dec 7, 2025

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)

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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
		}
	}()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

Copy link
Member

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...

Copy link
Member

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?

Copy link
Contributor Author

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

@andig
Copy link
Member

andig commented Dec 7, 2025

We can only merge this when issues are fixed. Amongst them lorenzodonini/ocpp-go#309

@andig andig added backlog Things to do later and removed enhancement New feature or request labels Dec 7, 2025
@xBlaz3kx
Copy link
Contributor Author

xBlaz3kx commented Dec 7, 2025

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

@andig
Copy link
Member

andig commented Dec 7, 2025

Bzw, great PRs- did you already join us on Slack?

@xBlaz3kx
Copy link
Contributor Author

xBlaz3kx commented Dec 7, 2025

Bzw, great PRs- did you already join us on Slack?

Thanks! I just did 😃

@xBlaz3kx xBlaz3kx force-pushed the chore/test-with-race branch from bc03751 to 6b5fd03 Compare December 7, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backlog Things to do later infrastructure Basic functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants