From 5894a8544d51c99f1356130b8b487bc93299fedd Mon Sep 17 00:00:00 2001 From: larsrc Date: Tue, 13 Apr 2021 11:42:30 -0700 Subject: [PATCH] Create BUILD file in worker tests directory instead of running tests from the parent directory. RELNOTES: None. PiperOrigin-RevId: 368261056 --- .../java/com/google/devtools/build/lib/BUILD | 90 +------------- .../google/devtools/build/lib/worker/BUILD | 115 ++++++++++++++++++ src/test/shell/integration/BUILD | 8 +- 3 files changed, 121 insertions(+), 92 deletions(-) create mode 100644 src/test/java/com/google/devtools/build/lib/worker/BUILD diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD index bb268c3c53b399..b873dcf3be214c 100644 --- a/src/test/java/com/google/devtools/build/lib/BUILD +++ b/src/test/java/com/google/devtools/build/lib/BUILD @@ -1,4 +1,4 @@ -load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test") +load("@rules_java//java:defs.bzl", "java_library", "java_test") package( default_visibility = [ @@ -52,6 +52,7 @@ filegroup( "//src/test/java/com/google/devtools/build/lib/testing/common:srcs", "//src/test/java/com/google/devtools/build/lib/testutil:srcs", "//src/test/java/com/google/devtools/build/lib/windows:srcs", + "//src/test/java/com/google/devtools/build/lib/worker:srcs", ], visibility = ["//src:__pkg__"], ) @@ -557,93 +558,6 @@ java_test( ], ) -java_test( - name = "worker-tests", - srcs = - glob([ - "worker/*Test.java", - ]) + [ - "worker/TestUtils.java", - ], - test_class = "com.google.devtools.build.lib.AllTests", - deps = [ - ":AllTests", - "//src/main/java/com/google/devtools/build/lib/actions", - "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", - "//src/main/java/com/google/devtools/build/lib/clock", - "//src/main/java/com/google/devtools/build/lib/collect/nestedset", - "//src/main/java/com/google/devtools/build/lib/events", - "//src/main/java/com/google/devtools/build/lib/exec:spawn_runner", - "//src/main/java/com/google/devtools/build/lib/exec/local", - "//src/main/java/com/google/devtools/build/lib/sandbox", - "//src/main/java/com/google/devtools/build/lib/shell", - "//src/main/java/com/google/devtools/build/lib/util", - "//src/main/java/com/google/devtools/build/lib/util:os", - "//src/main/java/com/google/devtools/build/lib/util:resource_converter", - "//src/main/java/com/google/devtools/build/lib/vfs", - "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", - "//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs", - "//src/main/java/com/google/devtools/build/lib/worker", - "//src/main/java/com/google/devtools/common/options:options_internal", - "//src/main/protobuf:worker_protocol_java_proto", - "//src/test/java/com/google/devtools/build/lib/actions/util", - "//src/test/java/com/google/devtools/build/lib/events:testutil", - "//src/test/java/com/google/devtools/build/lib/testutil", - "//src/test/java/com/google/devtools/build/lib/testutil:JunitUtils", - "//src/test/java/com/google/devtools/build/lib/testutil:TestUtils", - "//src/test/java/com/google/devtools/build/lib/vfs/util", - "//third_party:apache_commons_pool2_checked_in", - "//third_party:gson", - "//third_party:guava", - "//third_party:guava-testlib", - "//third_party:junit4", - "//third_party:mockito", - "//third_party:truth", - "//third_party/protobuf:protobuf_java", - "//third_party/protobuf:protobuf_java_util", - ], -) - -java_library( - name = "ExampleWorker-lib", - srcs = glob(["worker/*ExampleWorker*.java"]), - visibility = [ - "//src/test/shell/integration:__pkg__", - ], - deps = [ - "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", - "//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers", - "//src/main/java/com/google/devtools/common/options", - "//src/main/protobuf:worker_protocol_java_proto", - "//third_party:gson", - "//third_party:guava", - "//third_party/protobuf:protobuf_java", - "//third_party/protobuf:protobuf_java_util", - ], -) - -java_binary( - name = "ExampleWorker", - main_class = "com.google.devtools.build.lib.worker.ExampleWorker", - visibility = [ - "//src/test/shell/integration:__pkg__", - ], - runtime_deps = [ - ":ExampleWorker-lib", - ], -) - -java_binary( - name = "ExampleWorkerMultiplexer", - main_class = "com.google.devtools.build.lib.worker.ExampleWorkerMultiplexer", - visibility = [ - "//src/test/shell/integration:__pkg__", - ], - runtime_deps = [ - ":ExampleWorker-lib", - ], -) - TEST_SUITES = [ "ziputils", "rules", diff --git a/src/test/java/com/google/devtools/build/lib/worker/BUILD b/src/test/java/com/google/devtools/build/lib/worker/BUILD new file mode 100644 index 00000000000000..88afc7f3de68f5 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/worker/BUILD @@ -0,0 +1,115 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test") + +package( + default_testonly = 1, + default_visibility = ["//src:__subpackages__"], +) + +filegroup( + name = "srcs", + testonly = 0, + srcs = glob(["*"]), + visibility = ["//src:__subpackages__"], +) + +java_library( + name = "ExampleWorker_lib", + srcs = [ + "ExampleWorker.java", + "ExampleWorkerMultiplexer.java", + "ExampleWorkerMultiplexerOptions.java", + "ExampleWorkerOptions.java", + "ExampleWorkerProtocol.java", + ], + deps = [ + "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", + "//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers", + "//src/main/java/com/google/devtools/common/options", + "//src/main/protobuf:worker_protocol_java_proto", + "//third_party:gson", + "//third_party:guava", + ], +) + +java_library( + name = "testutil", + testonly = 1, + srcs = ["TestUtils.java"], + deps = [ + "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", + "//src/main/java/com/google/devtools/build/lib/shell", + "//src/main/java/com/google/devtools/build/lib/vfs", + "//src/main/java/com/google/devtools/build/lib/worker", + "//third_party:guava", + ], +) + +java_binary( + name = "ExampleWorker", + main_class = "com.google.devtools.build.lib.worker.ExampleWorker", + runtime_deps = [":ExampleWorker_lib"], +) + +java_binary( + name = "ExampleWorkerMultiplexer", + main_class = "com.google.devtools.build.lib.worker.ExampleWorkerMultiplexer", + runtime_deps = [":ExampleWorker_lib"], +) + +java_library( + name = "WorkerTests_lib", + srcs = glob(["*Test.java"]), + deps = [ + ":testutil", + "//src/main/java/com/google/devtools/build/lib/actions", + "//src/main/java/com/google/devtools/build/lib/actions:execution_requirements", + "//src/main/java/com/google/devtools/build/lib/clock", + "//src/main/java/com/google/devtools/build/lib/collect/nestedset", + "//src/main/java/com/google/devtools/build/lib/events", + "//src/main/java/com/google/devtools/build/lib/exec:spawn_runner", + "//src/main/java/com/google/devtools/build/lib/exec/local", + "//src/main/java/com/google/devtools/build/lib/sandbox", + "//src/main/java/com/google/devtools/build/lib/util:resource_converter", + "//src/main/java/com/google/devtools/build/lib/vfs", + "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment", + "//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs", + "//src/main/java/com/google/devtools/build/lib/worker", + "//src/main/java/com/google/devtools/common/options", + "//src/main/protobuf:worker_protocol_java_proto", + "//src/test/java/com/google/devtools/build/lib/actions/util", + "//src/test/java/com/google/devtools/build/lib/testutil:TestUtils", + "//src/test/java/com/google/devtools/build/lib/vfs/util", + "//third_party:apache_commons_pool2", + "//third_party:guava", + "//third_party:guava-testlib", + "//third_party:junit4", + "//third_party:mockito", + "//third_party:truth", + "//third_party/protobuf:protobuf_java", + ], +) + +java_test( + name = "WorkerTests", + size = "small", + data = [ + "//src/test/java/com/google/devtools/build/lib:embedded_scripts", + ], + test_class = "com.google.devtools.build.lib.AllTests", + runtime_deps = [ + ":WorkerTests_lib", + "//src/test/java/com/google/devtools/build/lib:test_runner", + ], +) + +java_test( + name = "WorkRequestHandlerTest", + srcs = ["WorkRequestHandlerTest.java"], + deps = [ + "//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers", + "//src/main/protobuf:worker_protocol_java_proto", + "//third_party:junit4", + "//third_party:mockito", + "//third_party:truth", + ], +) diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index fc10372e9d0d57..32a3a36b5c1860 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -510,7 +510,7 @@ sh_test( ], data = [ ":test-deps", - "//src/test/java/com/google/devtools/build/lib:ExampleWorker_deploy.jar", + "//src/test/java/com/google/devtools/build/lib/worker:ExampleWorker_deploy.jar", ], shard_count = 3, tags = [ @@ -529,7 +529,7 @@ sh_test( ], data = [ ":test-deps", - "//src/test/java/com/google/devtools/build/lib:ExampleWorker_deploy.jar", + "//src/test/java/com/google/devtools/build/lib/worker:ExampleWorker_deploy.jar", ], tags = [ "no_windows", @@ -547,7 +547,7 @@ sh_test( ], data = [ ":test-deps", - "//src/test/java/com/google/devtools/build/lib:ExampleWorkerMultiplexer_deploy.jar", + "//src/test/java/com/google/devtools/build/lib/worker:ExampleWorkerMultiplexer_deploy.jar", ], shard_count = 3, tags = [ @@ -566,7 +566,7 @@ sh_test( ], data = [ ":test-deps", - "//src/test/java/com/google/devtools/build/lib:ExampleWorker_deploy.jar", + "//src/test/java/com/google/devtools/build/lib/worker:ExampleWorker_deploy.jar", ], # TODO(b/34450149): remove when no longer flaky flaky = 1,