Skip to content

Commit 730da69

Browse files
committed
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.
1 parent 073862e commit 730da69

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/testing/benchmark.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func (b *B) ReportAllocs() {
159159

160160
// runN runs a single benchmark for the specified number of iterations.
161161
func (b *B) runN(n int) {
162+
b.runCleanup() // start fresh in the next iteration
162163
b.N = n
163164
runtime.GC()
164165
b.ResetTimer()
@@ -457,6 +458,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
457458
// Only process sub-benchmarks, if any.
458459
sub.hasSub = true
459460
}
461+
defer sub.runCleanup() // make sure all cleanups are run, even when panicking
460462
if sub.run1() {
461463
sub.run()
462464
}

0 commit comments

Comments
 (0)