Skip to content

Commit 65e9200

Browse files
committed
slog: make allocation tests less sensitive to compiler improvements
The compiler improved during the Go 1.25 cycle to reduce user allocations in some cases. In particular, CL 649079 avoids allocations by better recognition of literals that are later used in interface conversions. This now causes a few cases in TestAlloc to fail due to the improvement. This CL changes TestAlloc to treat the desired number of allocs as a maximum allowed, rather than a stricter equality check. In general, there are some trade-offs for whether to check for equality in allocation tests, but here it seems likely better to be more lenient toward compiler improvements, including given x/exp/slog is used with older versions of the Go compiler. Fixes golang/go#73928 Change-Id: I9643cb5d43d2cc567e616d67c84382fe7279f64f Reviewed-on: https://go-review.googlesource.com/c/exp/+/677595 Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> TryBot-Bypass: Carlos Amedee <[email protected]>
1 parent ce4c2cf commit 65e9200

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

slog/norace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import "testing"
1111
func wantAllocs(t *testing.T, want int, f func()) {
1212
t.Helper()
1313
got := int(testing.AllocsPerRun(5, f))
14-
if got != want {
15-
t.Errorf("got %d allocs, want %d", got, want)
14+
if got > want {
15+
t.Errorf("got %d allocs, want at most %d", got, want)
1616
}
1717
}

0 commit comments

Comments
 (0)