testing: run cleanups after exiting a benchmark run

This is important, otherwise temporary directories don't get removed.

Issue found while working on Go 1.20 support.
This commit is contained in:
Ayke van Laethem
2023-01-14 18:53:05 +01:00
parent 073862ee92
commit 730da698a3
+2
View File
@@ -159,6 +159,7 @@ func (b *B) ReportAllocs() {
// runN runs a single benchmark for the specified number of iterations.
func (b *B) runN(n int) {
b.runCleanup() // start fresh in the next iteration
b.N = n
runtime.GC()
b.ResetTimer()
@@ -457,6 +458,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
// Only process sub-benchmarks, if any.
sub.hasSub = true
}
defer sub.runCleanup() // make sure all cleanups are run, even when panicking
if sub.run1() {
sub.run()
}