@@ -29,6 +29,7 @@ import (
2929 "os"
3030 "path"
3131 "regexp"
32+ "slices"
3233 "strings"
3334 "sync"
3435 "testing"
@@ -1115,6 +1116,32 @@ func featureGatesMerge(src map[featuregate.Feature]bool, overrides map[featurega
11151116 return result
11161117}
11171118
1119+ // fixJSONOutput works around Go not emitting a "pass" action for
1120+ // sub-benchmarks
1121+ // (https://github.com/golang/go/issues/66825#issuecomment-2343229005), which
1122+ // causes gotestsum to report a successful benchmark run as failed
1123+ // (https://github.com/gotestyourself/gotestsum/issues/413#issuecomment-2343206787).
1124+ //
1125+ // It does this by printing the missing "PASS" output line that test2json
1126+ // then converts into the "pass" action.
1127+ func fixJSONOutput (b * testing.B ) {
1128+ if ! slices .Contains (os .Args , "-test.v=test2json" ) {
1129+ // Not printing JSON.
1130+ return
1131+ }
1132+
1133+ start := time .Now ()
1134+ b .Cleanup (func () {
1135+ if b .Failed () {
1136+ // Really has failed, do nothing.
1137+ return
1138+ }
1139+ // SYN gets injected when using -test.v=test2json, see
1140+ // https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/testing/testing.go;drc=87ec2c959c73e62bfae230ef7efca11ec2a90804;l=527
1141+ fmt .Fprintf (os .Stderr , "%c--- PASS: %s (%.2fs)\n " , 22 /* SYN */ , b .Name (), time .Since (start ).Seconds ())
1142+ })
1143+ }
1144+
11181145// RunBenchmarkPerfScheduling runs the scheduler performance benchmark tests.
11191146//
11201147// You can pass your own scheduler plugins via outOfTreePluginRegistry.
@@ -1128,6 +1155,7 @@ func RunBenchmarkPerfScheduling(b *testing.B, configFile string, topicName strin
11281155 if err = validateTestCases (testCases ); err != nil {
11291156 b .Fatal (err )
11301157 }
1158+ fixJSONOutput (b )
11311159
11321160 if testing .Short () {
11331161 PerfSchedulingLabelFilter += ",+short"
@@ -1147,11 +1175,13 @@ func RunBenchmarkPerfScheduling(b *testing.B, configFile string, topicName strin
11471175 dataItems := DataItems {Version : "v1" }
11481176 for _ , tc := range testCases {
11491177 b .Run (tc .Name , func (b * testing.B ) {
1178+ fixJSONOutput (b )
11501179 for _ , w := range tc .Workloads {
11511180 b .Run (w .Name , func (b * testing.B ) {
11521181 if ! enabled (testcaseLabelSelectors , append (tc .Labels , w .Labels ... )... ) {
11531182 b .Skipf ("disabled by label filter %q" , PerfSchedulingLabelFilter )
11541183 }
1184+ fixJSONOutput (b )
11551185
11561186 featureGates := featureGatesMerge (tc .FeatureGates , w .FeatureGates )
11571187 informerFactory , tCtx := setupTestCase (b , tc , featureGates , output , outOfTreePluginRegistry )
0 commit comments