Skip to content

Commit 3889649

Browse files
committed
bench/rttanalysis: shard TestBenchmarkExpectation to avoid timeouts
Re-apply `9fecc53b0b3cde307b5379ee5b88fae0fc8f34e2`, but add a `skip` if the test is running under `s390x`. Release note: none Epic: none
1 parent 4c40f45 commit 3889649

File tree

3 files changed

+103
-12
lines changed

3 files changed

+103
-12
lines changed

pkg/bench/rttanalysis/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ go_library(
1313
visibility = ["//visibility:public"],
1414
deps = [
1515
"//pkg/base",
16+
"//pkg/jobs",
17+
"//pkg/jobs/jobspb",
1618
"//pkg/kv/kvclient/kvcoord",
1719
"//pkg/sql",
1820
"//pkg/sql/parser",
@@ -56,9 +58,9 @@ go_test(
5658
data = glob(["testdata/**"]),
5759
embed = [":rttanalysis"],
5860
exec_properties = {"test.Pool": "large"},
61+
shard_count = 4,
5962
deps = [
6063
"//pkg/base",
61-
"//pkg/jobs",
6264
"//pkg/jobs/jobspb",
6365
"//pkg/security/securityassets",
6466
"//pkg/security/securitytest",
@@ -70,6 +72,7 @@ go_test(
7072
"//pkg/testutils/serverutils",
7173
"//pkg/testutils/skip",
7274
"//pkg/testutils/testcluster",
75+
"//pkg/util/envutil",
7376
"//pkg/util/protoutil",
7477
"//pkg/util/randutil",
7578
],

pkg/bench/rttanalysis/registry.go

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
package rttanalysis
77

88
import (
9+
"runtime"
910
"strings"
1011
"testing"
1112

13+
"github.com/cockroachdb/cockroach/pkg/jobs"
14+
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
1215
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
1316
"github.com/cockroachdb/errors"
1417
"github.com/stretchr/testify/require"
@@ -51,15 +54,69 @@ func (r *Registry) Run(b *testing.B) {
5154
// benchmarks can be filtered by passing the usual test filters underneath
5255
// this test's name.
5356
//
54-
// It takes a long time and thus is skipped under stress, race
55-
// and short.
57+
// It takes a long time and thus is skipped under duress and short.
5658
func (r *Registry) RunExpectations(t *testing.T) {
57-
skip.UnderStress(t)
58-
skip.UnderRace(t)
59+
r.RunExpectationsSharded(t, 1, 1)
60+
}
61+
62+
// RunExpectationsSharded runs all the benchmarks for one iteration
63+
// and validates that the number of RPCs meets the expectation. If run
64+
// with the --rewrite flag, it will rewrite the run benchmarks. The
65+
// benchmarks can be filtered by passing the usual test filters underneath
66+
// this test's name.
67+
//
68+
// It takes a long time and thus is skipped under duress and short.
69+
//
70+
// When shard and totalShards are provided (> 1), only a subset of benchmarks
71+
// assigned to the specific shard will be run, enabling parallel execution.
72+
// Test groups are distributed across shards using round-robin assignment.
73+
func (r *Registry) RunExpectationsSharded(t *testing.T, shard, totalShards int) {
74+
defer jobs.TestingSetIDsToIgnore(map[jobspb.JobID]struct{}{3001: {}, 3002: {}})()
75+
skip.UnderDuress(t)
5976
skip.UnderShort(t)
60-
skip.UnderDeadlock(t)
77+
if runtime.GOARCH == "s390x" {
78+
skip.IgnoreLint(t, "test prone to crashing under s390x (see #154317)")
79+
}
80+
81+
// If totalShards is 1, run all tests; otherwise shard them
82+
var registryToUse *Registry
83+
if totalShards <= 1 {
84+
// Run all test groups
85+
registryToUse = r
86+
} else {
87+
// Create a registry with only the test groups assigned to this shard
88+
shardRegistry := &Registry{
89+
numNodes: r.numNodes,
90+
cc: r.cc,
91+
r: make(map[string][]RoundTripBenchTestCase),
92+
}
93+
94+
// Distribute test groups across shards using round-robin assignment
95+
// First, get all group names and sort them for consistent ordering
96+
groupNames := make([]string, 0, len(r.r))
97+
for groupName := range r.r {
98+
groupNames = append(groupNames, groupName)
99+
}
100+
// Sort for deterministic assignment across runs
101+
for i := 0; i < len(groupNames); i++ {
102+
for j := i + 1; j < len(groupNames); j++ {
103+
if groupNames[i] > groupNames[j] {
104+
groupNames[i], groupNames[j] = groupNames[j], groupNames[i]
105+
}
106+
}
107+
}
108+
109+
// Assign groups to shards using round-robin
110+
for i, groupName := range groupNames {
111+
assignedShard := (i % totalShards) + 1
112+
if assignedShard == shard {
113+
shardRegistry.r[groupName] = r.r[groupName]
114+
}
115+
}
116+
registryToUse = shardRegistry
117+
}
61118

62-
runBenchmarkExpectationTests(t, r)
119+
runBenchmarkExpectationTests(t, registryToUse)
63120
}
64121

65122
// Register registers a set of test cases to a given benchmark name. It is

pkg/bench/rttanalysis/validate_benchmark_data_test.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,44 @@
66
package rttanalysis
77

88
import (
9+
"strconv"
910
"testing"
1011

11-
"github.com/cockroachdb/cockroach/pkg/jobs"
12-
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
12+
"github.com/cockroachdb/cockroach/pkg/util/envutil"
1313
)
1414

15-
func TestBenchmarkExpectation(t *testing.T) {
16-
defer jobs.TestingSetIDsToIgnore(map[jobspb.JobID]struct{}{3001: {}, 3002: {}})()
17-
reg.RunExpectations(t)
15+
// NOTE: If you change the number of shards, you must also update the
16+
// shard_count in BUILD.bazel to match.
17+
const shardCount = 4
18+
19+
// Validate that shardCount matches TEST_TOTAL_SHARDS environment variable at init time
20+
var _ = func() int {
21+
totalShardsStr, found := envutil.ExternalEnvString("TEST_TOTAL_SHARDS", 1)
22+
if totalShardsStr == "" || !found {
23+
return 0
24+
}
25+
totalShards, err := strconv.Atoi(totalShardsStr)
26+
if err != nil {
27+
return 0
28+
}
29+
if totalShards != shardCount {
30+
panic("shardCount mismatch: update shard_count in pkg/bench/rttanalysis/BUILD.bazel to match shardCount constant")
31+
}
32+
return 0
33+
}()
34+
35+
func TestBenchmarkExpectationShard1(t *testing.T) {
36+
reg.RunExpectationsSharded(t, 1, shardCount)
37+
}
38+
39+
func TestBenchmarkExpectationShard2(t *testing.T) {
40+
reg.RunExpectationsSharded(t, 2, shardCount)
41+
}
42+
43+
func TestBenchmarkExpectationShard3(t *testing.T) {
44+
reg.RunExpectationsSharded(t, 3, shardCount)
45+
}
46+
47+
func TestBenchmarkExpectationShard4(t *testing.T) {
48+
reg.RunExpectationsSharded(t, 4, shardCount)
1849
}

0 commit comments

Comments
 (0)