Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions testing/fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ find . -type f -name "*.go" -not -name "*_test.go" -exec sed -i 's|"testing"|tes
# Restore CodSpeed-specific files
restore_files "${CODSPEED_FILES[@]}"

apply_patch "patches/benchmark_stopbenchmark_fail.patch" 10 ".."

# Run pre-commit and format the code
go fmt ./... > /dev/null 2>&1 || true
pre-commit run --all-files > /dev/null 2>&1 || true
22 changes: 22 additions & 0 deletions testing/patches/benchmark_stopbenchmark_fail.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/testing/testing/benchmark.go b/testing/testing/benchmark.go
index e7e4d06..8fdea90 100644
--- a/testing/testing/benchmark.go
+++ b/testing/testing/benchmark.go
@@ -325,6 +325,8 @@ func (b *B) run1() bool {
}()
<-b.signal
if b.failed {
+ // This case can happen with a `b.Loop()` benchmark if any of the iterations fail
+ ensureBenchmarkIsStopped(b)
fmt.Fprintf(b.w, "%s--- FAIL: %s\n%s", b.chatty.prefix(), b.name, b.output)
return false
}
@@ -888,6 +890,8 @@ func (s *benchState) processBench(b *B) {
}
r := b.doBench()
if b.failed {
+ ensureBenchmarkIsStopped(b)
+
// The output could be very long here, but probably isn't.
// We print it all, regardless, because we don't want to trim the reason
// the benchmark failed.
4 changes: 4 additions & 0 deletions testing/testing/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ func (b *B) run1() bool {
}()
<-b.signal
if b.failed {
// This case can happen with a `b.Loop()` benchmark if any of the iterations fail
ensureBenchmarkIsStopped(b)
fmt.Fprintf(b.w, "%s--- FAIL: %s\n%s", b.chatty.prefix(), b.name, b.output)
return false
}
Expand Down Expand Up @@ -888,6 +890,8 @@ func (s *benchState) processBench(b *B) {
}
r := b.doBench()
if b.failed {
ensureBenchmarkIsStopped(b)

// The output could be very long here, but probably isn't.
// We print it all, regardless, because we don't want to trim the reason
// the benchmark failed.
Expand Down
8 changes: 8 additions & 0 deletions testing/testing/codspeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ func getGitRelativePath(absPath string) string {

return filepath.Join(goRunnerMetadata.RelativePackagePath, cwdRelativePath)
}

// If the benchmark execution failed, we have to ensure to stop the benchmark, which
// will send the event to the runner to also stop perf. Otherwise we could possibly
// sample a lot of data that isn't relevant. Additionally, we want to ensure that
// the emitted markers are correct (otherwise we'd have a SampleStart without a SampleStop).
func ensureBenchmarkIsStopped(b *B) {
b.codspeed.instrument_hooks.StopBenchmark()
}
Loading