Skip to content

Commit

Permalink
roachtest: convert tags from []string to map[string]struct{}
Browse files Browse the repository at this point in the history
  • Loading branch information
Miral Gadani committed Apr 4, 2023
1 parent 2086e3a commit 569aafb
Show file tree
Hide file tree
Showing 49 changed files with 107 additions and 101 deletions.
5 changes: 5 additions & 0 deletions pkg/cmd/roachtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Examples:
}
listCmd.Flags().BoolVar(
&listBench, "bench", false, "list benchmarks instead of tests")
listCmd.Flags().StringVar(
&cloud, "cloud", cloud, "cloud provider to use (aws, azure, or gce)")

var runCmd = &cobra.Command{
// Don't display usage when tests fail.
Expand Down Expand Up @@ -405,6 +407,9 @@ func runTests(register func(registry.Registry), cfg cliCfg) error {
return fmt.Errorf("--count (%d) must by greater than 0", cfg.count)
}
r := makeTestRegistry(cloud, instanceType, zonesF, localSSDArg)

// actual registering of tests
// TODO: don't register if we can't run on the specified registry cloud
register(&r)
cr := newClusterRegistry()
stopper := stop.NewStopper()
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/roachtest/registry/test_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type TestSpec struct {
// Tags is a set of tags associated with the test that allow grouping
// tests. If no tags are specified, the set ["default"] is automatically
// given.
Tags []string
Tags map[string]struct{}
// Cluster provides the specification for the cluster to use for the test.
Cluster spec.ClusterSpec
// NativeLibs specifies the native libraries required to be present on
Expand Down Expand Up @@ -137,10 +137,9 @@ func (t *TestSpec) Match(filter *TestFilter) MatchType {
return Matched
}

testTags := stringSliceToSet(t.Tags)
for tag := range filter.Tags {
// If the tag is a single CSV e.g. "foo,bar,baz", we match all the tags
if matchesAll(testTags, strings.Split(tag, ",")) {
if matchesAll(t.Tags, strings.Split(tag, ",")) {
return Matched
}
}
Expand Down Expand Up @@ -172,9 +171,10 @@ func matchesAll(testTags map[string]struct{}, filterTags []string) bool {
return true
}

func stringSliceToSet(slice []string) map[string]struct{} {
// Tags returns a set of strings.
func Tags(values ...string) map[string]struct{} {
set := make(map[string]struct{})
for _, s := range slice {
for _, s := range values {
set[s] = struct{}{}
}
return set
Expand Down
10 changes: 4 additions & 6 deletions pkg/cmd/roachtest/test_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (r *testRegistryImpl) prepareSpec(spec *registry.TestSpec) error {
return fmt.Errorf(`%s: unknown owner [%s]`, spec.Name, spec.Owner)
}
if len(spec.Tags) == 0 {
spec.Tags = []string{registry.DefaultTag}
spec.Tags = registry.Tags(registry.DefaultTag)
}
spec.Tags = append(spec.Tags, "owner-"+string(spec.Owner))
spec.Tags["owner-"+string(spec.Owner)] = struct{}{}

// At the time of writing, we expect the roachtest job to finish within 24h
// and have corresponding timeouts set up in CI. Since each individual test
Expand All @@ -127,10 +127,8 @@ func (r *testRegistryImpl) prepareSpec(spec *registry.TestSpec) error {
const maxTimeout = 18 * time.Hour
if spec.Timeout > maxTimeout {
var weekly bool
for _, tag := range spec.Tags {
if tag == "weekly" {
weekly = true
}
if _, ok := spec.Tags["weekly"]; ok {
weekly = true
}
if !weekly {
return fmt.Errorf(
Expand Down
28 changes: 14 additions & 14 deletions pkg/cmd/roachtest/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ func TestMatchOrSkip(t *testing.T) {
testCases := []struct {
filter []string
name string
tags []string
tags map[string]struct{}
expected registry.MatchType
}{
{nil, "foo", nil, registry.Matched},
{nil, "foo", []string{"bar"}, registry.Matched},
{[]string{"tag:bar"}, "foo", []string{"bar"}, registry.Matched},
{nil, "foo", registry.Tags("bar"), registry.Matched},
{[]string{"tag:bar"}, "foo", registry.Tags("bar"), registry.Matched},
// Partial tag match is not supported
{[]string{"tag:b"}, "foo", []string{"bar"}, registry.FailedTags},
{[]string{"tag:b"}, "foo", registry.Tags("bar"), registry.FailedTags},
{[]string{"tag:b"}, "foo", nil, registry.FailedTags},
{[]string{"tag:f"}, "foo", []string{"bar"}, registry.FailedTags},
{[]string{"tag:f"}, "foo", registry.Tags("bar"), registry.FailedTags},
// Specifying no tag filters matches all tags.
{[]string{"f"}, "foo", []string{"bar"}, registry.Matched},
{[]string{"f"}, "bar", []string{"bar"}, registry.FailedFilter},
{[]string{"f", "tag:bar"}, "foo", []string{"bar"}, registry.Matched},
{[]string{"f", "tag:b"}, "foo", []string{"bar"}, registry.FailedTags},
{[]string{"f", "tag:f"}, "foo", []string{"bar"}, registry.FailedTags},
{[]string{"f"}, "foo", registry.Tags("bar"), registry.Matched},
{[]string{"f"}, "bar", registry.Tags("bar"), registry.FailedFilter},
{[]string{"f", "tag:bar"}, "foo", registry.Tags("bar"), registry.Matched},
{[]string{"f", "tag:b"}, "foo", registry.Tags("bar"), registry.FailedTags},
{[]string{"f", "tag:f"}, "foo", registry.Tags("bar"), registry.FailedTags},
// Match tests that have both tags 'abc' and 'bar'
{[]string{"f", "tag:abc,bar"}, "foo", []string{"abc", "bar"}, registry.Matched},
{[]string{"f", "tag:abc,bar"}, "foo", []string{"abc"}, registry.FailedTags},
{[]string{"f", "tag:abc,bar"}, "foo", registry.Tags("abc", "bar"), registry.Matched},
{[]string{"f", "tag:abc,bar"}, "foo", registry.Tags("abc"), registry.FailedTags},
// Match tests that have tag 'abc' but not 'bar'
{[]string{"f", "tag:abc,!bar"}, "foo", []string{"abc"}, registry.Matched},
{[]string{"f", "tag:abc,!bar"}, "foo", []string{"abc", "bar"}, registry.FailedTags},
{[]string{"f", "tag:abc,!bar"}, "foo", registry.Tags("abc"), registry.Matched},
{[]string{"f", "tag:abc,!bar"}, "foo", registry.Tags("abc", "bar"), registry.FailedTags},
}
for _, c := range testCases {
t.Run("", func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/roachtest/tests/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func registerAcceptance(r registry.Registry) {
},
},
}
tags := []string{"default", "quick"}
specTemplate := registry.TestSpec{
// NB: teamcity-post-failures.py relies on the acceptance tests
// being named acceptance/<testname> and will avoid posting a
Expand All @@ -86,7 +85,7 @@ func registerAcceptance(r registry.Registry) {
// will be posted.
Name: "acceptance",
Timeout: 10 * time.Minute,
Tags: tags,
Tags: registry.Tags("default", "quick"),
}

for owner, tests := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/activerecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func registerActiveRecord(r registry.Registry) {
Timeout: 5 * time.Hour,
Cluster: r.MakeClusterSpec(1),
NativeLibs: registry.LibGEOS,
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: runActiveRecord,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func registerElasticControlForBackups(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "admission-control/elastic-backup",
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(4, spec.CPU(8)),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
if c.Spec().NodeCount < 4 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/admission_control_elastic_cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func registerElasticControlForCDC(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "admission-control/elastic-cdc",
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(4, spec.CPU(8)),
RequiresLicense: true,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func registerIndexOverload(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "admission-control/index-overload",
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags("weekly"),
Cluster: r.MakeClusterSpec(4, spec.CPU(8)),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
crdbNodes := c.Spec().NodeCount - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func registerMultiStoreOverload(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "admission-control/multi-store-with-overload",
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(2, spec.CPU(8), spec.SSD(2)),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runKV(ctx, t, c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func registerSnapshotOverload(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "admission-control/snapshot-overload",
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(4, spec.CPU(8)),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
if c.Spec().NodeCount < 4 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/admission_control_tpcc_overload.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func registerTPCCOverload(r registry.Registry) {
r.Add(registry.TestSpec{
Name: name,
Owner: registry.OwnerAdmissionControl,
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(s.Nodes+1, spec.CPU(s.CPUs)),
Run: s.run,
EncryptionSupport: registry.EncryptionMetamorphic,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/asyncpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func registerAsyncpg(r registry.Registry) {
Name: "asyncpg",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1, spec.CPU(16)),
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runAsyncpg(ctx, t, c)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/awsdms.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func registerAWSDMS(r registry.Registry) {
Name: "awsdms",
Owner: registry.OwnerSQLSessions, // TODO(otan): add a migrations OWNERS team
Cluster: r.MakeClusterSpec(1),
Tags: []string{`default`, `awsdms`, `aws`},
Tags: registry.Tags(`default`, `awsdms`, `aws`),
Run: runAWSDMS,
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/roachtest/tests/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,10 @@ func registerBackup(r registry.Registry) {
for _, item := range []struct {
kmsProvider string
machine string
tags []string
tags map[string]struct{}
}{
{kmsProvider: "GCS", machine: spec.GCE},
{kmsProvider: "AWS", machine: spec.AWS, tags: []string{"aws"}},
{kmsProvider: "AWS", machine: spec.AWS, tags: registry.Tags("aws")},
} {
item := item
r.Add(registry.TestSpec{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ func registerCDC(r registry.Registry) {
Name: "cdc/tpcc-1000/sink=null",
Owner: registry.OwnerCDC,
Cluster: r.MakeClusterSpec(4, spec.CPU(16)),
Tags: []string{"manual"},
Tags: registry.Tags("manual"),
RequiresLicense: true,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
ct := newCDCTester(ctx, t, c)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/roachtest/tests/cluster_to_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ type replicationTestSpec struct {
replicationStartHook func(ctx context.Context, sp *replicationTestSpec)

// tags are used to categorize the test.
tags []string
tags map[string]struct{}

// fields below are instantiated at runtime
setup *c2cSetup
Expand Down Expand Up @@ -719,7 +719,7 @@ func registerClusterToCluster(r registry.Registry) {
timeout: 1 * time.Hour,
additionalDuration: 10 * time.Minute,
cutover: 5 * time.Minute,
tags: []string{"aws"},
tags: registry.Tags("aws"),
},
{
name: "c2c/UnitTest",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/django.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func registerDjango(r registry.Registry) {
Name: "django",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1, spec.CPU(16)),
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runDjango(ctx, t, c)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func registerFixtures(r registry.Registry) {
spec := registry.TestSpec{
Name: "generate-fixtures",
Timeout: 30 * time.Minute,
Tags: []string{"fixtures"},
Tags: registry.Tags("fixtures"),
Owner: registry.OwnerDevInf,
Cluster: r.MakeClusterSpec(4),
Run: runFixtures,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/gopg.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func registerGopg(r registry.Registry) {
Name: "gopg",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runGopg(ctx, t, c)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func registerGORM(r registry.Registry) {
Name: "gorm",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: runGORM,
})
}
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/hibernate.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func registerHibernate(r registry.Registry, opt hibernateOptions) {
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
NativeLibs: registry.LibGEOS,
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runHibernate(ctx, t, c)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/jasyncsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func registerJasyncSQL(r registry.Registry) {
Name: "jasync",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runJasyncSQL(ctx, t, c)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/knex.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func registerKnex(r registry.Registry) {
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
NativeLibs: registry.LibGEOS,
Tags: []string{`default`, `orm`},
Tags: registry.Tags(`default`, `orm`),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runKnex(ctx, t, c)
},
Expand Down
18 changes: 11 additions & 7 deletions pkg/cmd/roachtest/tests/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func registerKV(r registry.Registry) {
raid0 bool
duration time.Duration
tracing bool // `trace.debug.enable`
tags []string
tags map[string]struct{}
owner registry.Owner // defaults to KV
}
computeNumSplits := func(opts kvOptions) int {
Expand Down Expand Up @@ -239,8 +239,8 @@ func registerKV(r registry.Registry) {
{nodes: 1, cpus: 32, readPercent: 95, spanReads: true, splits: -1 /* no splits */, disableLoadSplits: true, sequential: true},

// Weekly larger scale configurations.
{nodes: 32, cpus: 8, readPercent: 0, tags: []string{"weekly"}, duration: time.Hour},
{nodes: 32, cpus: 8, readPercent: 95, tags: []string{"weekly"}, duration: time.Hour},
{nodes: 32, cpus: 8, readPercent: 0, tags: registry.Tags("weekly"), duration: time.Hour},
{nodes: 32, cpus: 8, readPercent: 95, tags: registry.Tags("weekly"), duration: time.Hour},
} {
opts := opts

Expand All @@ -251,7 +251,11 @@ func registerKV(r registry.Registry) {
}
nameParts = append(nameParts, fmt.Sprintf("kv%d%s", opts.readPercent, limitedSpanStr))
if len(opts.tags) > 0 {
nameParts = append(nameParts, strings.Join(opts.tags, "/"))
var keys []string
for k := range opts.tags {
keys = append(keys, k)
}
nameParts = append(nameParts, strings.Join(keys, "/"))
}
nameParts = append(nameParts, fmt.Sprintf("enc=%t", opts.encryption))
nameParts = append(nameParts, fmt.Sprintf("nodes=%d", opts.nodes))
Expand Down Expand Up @@ -298,9 +302,9 @@ func registerKV(r registry.Registry) {
}
cSpec := r.MakeClusterSpec(opts.nodes+1, spec.CPU(opts.cpus), spec.SSD(opts.ssds), spec.RAID0(opts.raid0))

// All the kv0|95 tests not using ssd should run on AWS by default
// All the kv0|95 tests should run on AWS by default
if opts.tags == nil && opts.ssds == 0 && (opts.readPercent == 95 || opts.readPercent == 0) {
opts.tags = []string{"aws"}
opts.tags = registry.Tags("aws")
}

var skip string
Expand Down Expand Up @@ -937,7 +941,7 @@ func registerKVRestartImpact(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "kv/restart/nodes=12",
// This test is expensive (104vcpu), we run it weekly.
Tags: []string{`weekly`},
Tags: registry.Tags(`weekly`),
Owner: registry.OwnerKV,
Cluster: r.MakeClusterSpec(13, spec.CPU(8)),
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/kvbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func registerKVBenchSpec(r registry.Registry, b kvBenchSpec) {
// for --max-rate.
// TODO(andrei): output something to roachperf and start running them
// nightly.
Tags: []string{"manual"},
Tags: registry.Tags("manual"),
Owner: registry.OwnerKV,
Cluster: nodes,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/libpq.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func registerLibPQ(r registry.Registry) {
Name: "lib/pq",
Owner: registry.OwnerSQLSessions,
Cluster: r.MakeClusterSpec(1),
Tags: []string{`default`, `driver`},
Tags: registry.Tags(`default`, `driver`),
Run: runLibPQ,
})
}
Loading

0 comments on commit 569aafb

Please sign in to comment.