diff options
author | Fabian Meumertzheim <fabian@meumertzhe.im> | 2023-04-27 00:33:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 22:33:13 +0000 |
commit | 0ca1dcadc29883648692c0182c52a9ed31b32423 (patch) | |
tree | 07c3fe0a2346ac599ad91fd601fbdd9dd5690052 | |
parent | 2a7131169cceb41f787caf9a39d251cff948fa8d (diff) | |
download | bazelbuild-rules_go-0ca1dcadc29883648692c0182c52a9ed31b32423.tar.gz |
Create TEST_SHARD_STATUS_FILE when sharding tests (#3547)
Bazel claims to check that this file has been touched when sharding
tests. It currently doesn't, but that will change soon.
-rw-r--r-- | go/tools/builders/generate_test_main.go | 5 | ||||
-rw-r--r-- | tests/core/go_test/BUILD.bazel | 6 | ||||
-rw-r--r-- | tests/core/go_test/sharding_test.go | 13 |
3 files changed, 24 insertions, 0 deletions
diff --git a/go/tools/builders/generate_test_main.go b/go/tools/builders/generate_test_main.go index a85e110a..6d545b9d 100644 --- a/go/tools/builders/generate_test_main.go +++ b/go/tools/builders/generate_test_main.go @@ -146,6 +146,11 @@ func testsInShard() []testing.InternalTest { if err != nil || totalShards <= 1 { return allTests } + file, err := os.Create(os.Getenv("TEST_SHARD_STATUS_FILE")) + if err != nil { + log.Fatalf("Failed to touch TEST_SHARD_STATUS_FILE: %v", err) + } + _ = file.Close() shardIndex, err := strconv.Atoi(os.Getenv("TEST_SHARD_INDEX")) if err != nil || shardIndex < 0 { return allTests diff --git a/tests/core/go_test/BUILD.bazel b/tests/core/go_test/BUILD.bazel index f6f600d9..b77c851b 100644 --- a/tests/core/go_test/BUILD.bazel +++ b/tests/core/go_test/BUILD.bazel @@ -244,6 +244,12 @@ go_test( ], ) +go_test( + name = "sharding_test", + srcs = ["sharding_test.go"], + shard_count = 2, +) + go_bazel_test( name = "env_inherit_test", srcs = ["env_inherit_test.go"], diff --git a/tests/core/go_test/sharding_test.go b/tests/core/go_test/sharding_test.go new file mode 100644 index 00000000..a83bb85c --- /dev/null +++ b/tests/core/go_test/sharding_test.go @@ -0,0 +1,13 @@ +package sharding_test + +import ( + "log" + "os" + "testing" +) + +func TestShardStatusFile(t *testing.T) { + if _, err := os.Stat(os.Getenv("TEST_SHARD_STATUS_FILE")); err != nil { + log.Fatalf("Expected Go test runner to create TEST_SHARD_STATUS_FILE: %v", err) + } +} |