Skip to content

Commit b5a0c67

Browse files
aclementsbradfitz
authored andcommitted
test: force heap profile update in heapsampling.go test
The heapsampling.go test occasionally fails on some architectures because it finds zero heap samples in main.alloc. This happens because the byte and object counts are only updated at a GC. Hence, if a GC happens part way through allocInterleaved, but then doesn't happen after we start calling main.alloc, checkAllocations will see buckets for the lines in main.alloc (which are created eagerly), but the object and byte counts will be zero. Fix this by forcing a GC to update the profile before we collect it. Fixes #13098. Change-Id: Ia7a9918eea6399307f10499dd7abefd4f6d13cf6 Reviewed-on: https://go-review.googlesource.com/16846 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]>
1 parent d54c356 commit b5a0c67

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

test/heapsampling.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ var a64k *[64 * 1024]byte
2525
// vary for run to run. This test only checks that the resulting
2626
// values appear reasonable.
2727
func main() {
28-
return // TODO: fix this flaky test; golang.org/issue/13098
29-
3028
const countInterleaved = 10000
3129
allocInterleaved(countInterleaved)
3230
checkAllocations(getMemProfileRecords(), "main.allocInterleaved", countInterleaved, []int64{256 * 1024, 1024, 256 * 1024, 512, 256 * 1024, 256})
@@ -93,6 +91,9 @@ func checkValue(fname string, ln int, name string, want, got int64) {
9391
}
9492

9593
func getMemProfileRecords() []runtime.MemProfileRecord {
94+
// Force the runtime to update the object and byte counts.
95+
runtime.GC()
96+
9697
// Find out how many records there are (MemProfile(nil, true)),
9798
// allocate that many records, and get the data.
9899
// There's a race—more records might be added between

0 commit comments

Comments
 (0)