|
6 | 6 | package rttanalysis |
7 | 7 |
|
8 | 8 | import ( |
| 9 | + "runtime" |
9 | 10 | "strings" |
10 | 11 | "testing" |
11 | 12 |
|
| 13 | + "github.com/cockroachdb/cockroach/pkg/jobs" |
| 14 | + "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" |
12 | 15 | "github.com/cockroachdb/cockroach/pkg/testutils/skip" |
13 | 16 | "github.com/cockroachdb/errors" |
14 | 17 | "github.com/stretchr/testify/require" |
@@ -51,15 +54,69 @@ func (r *Registry) Run(b *testing.B) { |
51 | 54 | // benchmarks can be filtered by passing the usual test filters underneath |
52 | 55 | // this test's name. |
53 | 56 | // |
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. |
56 | 58 | 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) |
59 | 76 | 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 | + } |
61 | 118 |
|
62 | | - runBenchmarkExpectationTests(t, r) |
| 119 | + runBenchmarkExpectationTests(t, registryToUse) |
63 | 120 | } |
64 | 121 |
|
65 | 122 | // Register registers a set of test cases to a given benchmark name. It is |
|
0 commit comments