Skip to content

Commit ed16991

Browse files
committed
fix(testing): emit StopBenchmark command even when benches failed
1 parent 140fee0 commit ed16991

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

testing/fork.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ find . -type f -name "*.go" -not -name "*_test.go" -exec sed -i 's|"testing"|tes
120120
# Restore CodSpeed-specific files
121121
restore_files "${CODSPEED_FILES[@]}"
122122

123+
apply_patch "patches/benchmark_stopbenchmark_fail.patch" 10 ".."
124+
123125
# Run pre-commit and format the code
124126
go fmt ./... > /dev/null 2>&1 || true
125127
pre-commit run --all-files > /dev/null 2>&1 || true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/testing/testing/benchmark.go b/testing/testing/benchmark.go
2+
index e7e4d06..8fdea90 100644
3+
--- a/testing/testing/benchmark.go
4+
+++ b/testing/testing/benchmark.go
5+
@@ -325,6 +325,8 @@ func (b *B) run1() bool {
6+
}()
7+
<-b.signal
8+
if b.failed {
9+
+ // This case can happen with a `b.Loop()` benchmark if any of the iterations fail
10+
+ ensureBenchmarkIsStopped(b)
11+
fmt.Fprintf(b.w, "%s--- FAIL: %s\n%s", b.chatty.prefix(), b.name, b.output)
12+
return false
13+
}
14+
@@ -888,6 +890,8 @@ func (s *benchState) processBench(b *B) {
15+
}
16+
r := b.doBench()
17+
if b.failed {
18+
+ ensureBenchmarkIsStopped(b)
19+
+
20+
// The output could be very long here, but probably isn't.
21+
// We print it all, regardless, because we don't want to trim the reason
22+
// the benchmark failed.

testing/testing/benchmark.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ func (b *B) run1() bool {
325325
}()
326326
<-b.signal
327327
if b.failed {
328+
// This case can happen with a `b.Loop()` benchmark if any of the iterations fail
329+
ensureBenchmarkIsStopped(b)
328330
fmt.Fprintf(b.w, "%s--- FAIL: %s\n%s", b.chatty.prefix(), b.name, b.output)
329331
return false
330332
}
@@ -888,6 +890,8 @@ func (s *benchState) processBench(b *B) {
888890
}
889891
r := b.doBench()
890892
if b.failed {
893+
ensureBenchmarkIsStopped(b)
894+
891895
// The output could be very long here, but probably isn't.
892896
// We print it all, regardless, because we don't want to trim the reason
893897
// the benchmark failed.

testing/testing/codspeed.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ func getGitRelativePath(absPath string) string {
6666

6767
return filepath.Join(goRunnerMetadata.RelativePackagePath, cwdRelativePath)
6868
}
69+
70+
// If the benchmark execution failed, we have to ensure to stop the benchmark, which
71+
// will send the event to the runner to also stop perf. Otherwise we could possibly
72+
// sample a lot of data that isn't relevant. Additionally, we want to ensure that
73+
// the emitted markers are correct (otherwise we'd have a SampleStart without a SampleStop).
74+
func ensureBenchmarkIsStopped(b *B) {
75+
b.codspeed.instrument_hooks.StopBenchmark()
76+
}

0 commit comments

Comments
 (0)