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