[testsharder] Fail if tests in multipliers file not found in test
manifest.
Bug: IN-1460 #comment
Change-Id: I8b8927b0be6b6aefa65de96975ff5daab4dc8856
diff --git a/cmd/testsharder/main.go b/cmd/testsharder/main.go
index 54aebd8..a80d71c 100644
--- a/cmd/testsharder/main.go
+++ b/cmd/testsharder/main.go
@@ -77,7 +77,10 @@
if err != nil {
log.Fatal(err)
}
- shards = testsharder.MultiplyShards(shards, multipliers)
+ shards, err = testsharder.MultiplyShards(shards, multipliers)
+ if err != nil {
+ log.Fatal(err)
+ }
}
f := os.Stdout
if outputFile != "" {
diff --git a/testsharder/shard.go b/testsharder/shard.go
index 7edf452..067c8b4 100644
--- a/testsharder/shard.go
+++ b/testsharder/shard.go
@@ -75,7 +75,8 @@
// Appends new shards to shards where each new shard contains one test repeated
// multiple times according to the specifications in multipliers.
-func MultiplyShards(shards []*Shard, multipliers []TestModifier) []*Shard {
+func MultiplyShards(shards []*Shard, multipliers []TestModifier) ([]*Shard, error) {
+ multipliersFound := make(map[TestModifier]bool)
for _, shard := range shards {
for _, multiplier := range multipliers {
for _, test := range shard.Tests {
@@ -85,11 +86,15 @@
Tests: multiplyTest(test, multiplier.TotalRuns),
Env: shard.Env,
})
+ multipliersFound[multiplier] = true
}
}
}
}
- return shards
+ if len(multipliersFound) != len(multipliers) {
+ return nil, fmt.Errorf("Not all of the multiplier targets were found in the test manifest. Make sure the targets appear in $root_build_dir/tests.json")
+ }
+ return shards, nil
}
// Removes leading slashes and replaces all other `/` with `_`. This allows the
diff --git a/testsharder/shard_test.go b/testsharder/shard_test.go
index af92126..5ff524f 100644
--- a/testsharder/shard_test.go
+++ b/testsharder/shard_test.go
@@ -217,13 +217,13 @@
multShard := func(env Environment, os OS, id int, runs int) *Shard {
var tests []Test
test := makeTest(id, os)
- origName := test.Name
- for i := 0; i < runs; i++ {
- test.Name = fmt.Sprintf("%s (%d)", origName, i+1)
- tests = append(tests, test)
+ for i := 1; i <= runs; i++ {
+ testCopy := test
+ testCopy.Name = fmt.Sprintf("%s (%d)", test.Name, i)
+ tests = append(tests, testCopy)
}
return &Shard{
- Name: env.Name() + "-" + origName,
+ Name: env.Name() + "-" + test.Name,
Tests: tests,
Env: env,
}
@@ -239,10 +239,13 @@
makeTestModifier(1, Fuchsia, 2),
makeTestModifier(3, Linux, 3),
}
- actual := MultiplyShards(
+ actual, err := MultiplyShards(
shards,
multipliers,
)
+ if err != nil {
+ t.Fatalf("failed with errmsg: %v", err)
+ }
expected := append(
shards,
multShard(env1, Fuchsia, 1, 2),
@@ -251,4 +254,23 @@
)
assertEqual(t, expected, actual)
})
+
+ t.Run("fail to multiply shards with invalid multipliers", func(t *testing.T) {
+ shards := []*Shard{
+ shard(env1, Fuchsia, 1),
+ shard(env2, Fuchsia, 1, 2),
+ shard(env3, Linux, 3),
+ }
+ multipliers := []TestModifier{
+ makeTestModifier(1, Linux, 2),
+ makeTestModifier(3, Linux, 3),
+ }
+ _, err := MultiplyShards(
+ shards,
+ multipliers,
+ )
+ if err == nil {
+ t.Fatalf("did not fail for invalid multipliers")
+ }
+ })
}