Skip to content

Commit eaca054

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 776dabb commit eaca054

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
@@ -158,6 +158,7 @@ func (b *B) ReportAllocs() {
158158

159159
// runN runs a single benchmark for the specified number of iterations.
160160
func (b *B) runN(n int) {
161+
b.runCleanup() // start fresh in the next iteration
161162
b.N = n
162163
b.ResetTimer()
163164
b.StartTimer()
@@ -443,6 +444,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
443444
// Only process sub-benchmarks, if any.
444445
sub.hasSub = true
445446
}
447+
defer sub.runCleanup() // make sure all cleanups are run, even when panicking
446448
if sub.run1() {
447449
sub.run()
448450
}

0 commit comments

Comments
 (0)