-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Labels
Description
Bug Description
The Test_ToUpper/non-ascii test in the utils package fails in CI when run with gotestsum -f testname -- ./... -race -count=1 -shuffle=on, reporting 4 allocations instead of the expected 0 for the input "ยตรรครถรผ". This failure does not occur locally, with or without -race, suggesting that the CI environment and race detector are causing testing.AllocsPerRun to misreport allocations, possibly exacerbated by gotestsum's interaction with GOMAXPROCS.
Details
- Test Case: The
non-asciitest case expectsToUpperto return the input"ยตรรครถรผ"unchanged with zero allocations (upperNoConv: true), as non-ASCII bytes map to themselves intoUpperTable. - Failure: In CI, with
-race -shuffle=on,testing.AllocsPerRunreports 4 allocations, failing therequire.Zeroassertion:=== FAIL: . Test_ToUpper/non-ascii (0.01s) strings_test.go:93: Error Trace: /Users/runner/work/utils/utils/strings_test.go:93 Error: Should be zero, but was 4 Test: Test_ToUpper/non-ascii Messages: ToUpper should not allocate for non-ascii - Environment: The failure is specific to CI (e.g., GitHub Actions) with
-raceand-shuffle=on(seed: 1752474430640501000). Locally, the test passes with or without-race. - Suspected Cause: The Go race detector introduces additional allocations (e.g., 8 bytes per
deferandrecoverstatement, as per Go Race Detector Documentation), which are captured bytesting.AllocsPerRun. Additionally,gotestsummay interfere withtesting.AllocsPerRun's setting ofGOMAXPROCSto 1, potentially causing allocation misreporting in CI. This is supported by Go issues like #8734 and #5000, which discuss allocation counting inconsistencies. - Impact: The test failure is likely a false positive due to race detector overhead and/or
gotestsuminteractions, not a bug inToUpper, as the function correctly avoids allocations for non-ASCII inputs.
Steps to Reproduce
- Run tests in CI with:
gotestsum -f testname -- ./... -race -count=1 -shuffle=1752474430640501000 -v
- Observe the failure in
Test_ToUpper/non-ascii, reporting 4 allocations instead of 0.
Expected Behavior
Test_ToUpper/non-asciishould pass with zero allocations, asToUpperreturns the input string unchanged for"ยตรรครถรผ".- Allocation tests should be reliable even with
-raceandgotestsum.
Actual Behavior
- In CI with
-race,testing.AllocsPerRunreports 4 allocations, causing the test to fail.
Proposed Debugging
Add a diagnostic test to log allocation details for debugging:
func Test_ToUpper_NonASCII_Allocations(t *testing.T) {
t.Parallel()
input := "ยตรรครถรผ"
allocs := testing.AllocsPerRun(100, func() {
result := ToUpper(input)
if result != input {
t.Errorf("ToUpper modified input: got %v, want %v", result, input)
}
})
t.Logf("Bytes: %v", []byte(input))
t.Logf("Allocations for ToUpper(ยตรรครถรผ): %f", allocs)
if os.Getenv("RACE") != "1" {
require.Zero(t, allocs, "ToUpper should not allocate for non-ascii")
}
}Alternatively, investigate if gotestsum affects GOMAXPROCS settings by running tests without gotestsum:
go test -race -count=1 -shuffle=1752474430640501000 -v ./...Additional Notes
- Go Version: Verify the Go version in CI vs. locally (e.g.,
go version). Differences may affect runtime behavior. - References:
Reactions are currently unavailable