diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java index 48394f478222fa..334ac63f9b8823 100644 --- a/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java +++ b/src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java @@ -87,7 +87,11 @@ public void setup(BlackBoxTestContext context) throws IOException { } } - lines.add("common --enable_bzlmod"); + if (OS.getCurrent() == OS.DARWIN) { + // Prefer ipv6 network on macOS + lines.add("startup --host_jvm_args=-Djava.net.preferIPv6Addresses=true"); + lines.add("build --jvmopt=-Djava.net.preferIPv6Addresses"); + } context.write(".bazelrc", lines); } diff --git a/src/test/py/bazel/remote/cache_decompression_test.py b/src/test/py/bazel/remote/cache_decompression_test.py index f297a0cd3acf45..e6ca6cde47c112 100644 --- a/src/test/py/bazel/remote/cache_decompression_test.py +++ b/src/test/py/bazel/remote/cache_decompression_test.py @@ -64,12 +64,21 @@ def do_GET(self): self.finish() +class HTTPServerV6(HTTPServer): + address_family = socket.AF_INET6 + + class CacheDecompressionTest(test_base.TestBase): def setUp(self): test_base.TestBase.setUp(self) server_port = self.GetFreeTCPPort() - self.httpd = HTTPServer(('localhost', server_port), MemoryStorageHandler) + if self.IsDarwin(): + self.httpd = HTTPServerV6( + ('localhost', server_port), MemoryStorageHandler + ) + else: + self.httpd = HTTPServer(('localhost', server_port), MemoryStorageHandler) self.httpd.storage = {} self.url = 'http://localhost:{}'.format(server_port) self.background = threading.Thread(target=self.httpd.serve_forever) diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index 9f8e7cb4d517f4..58069c80c95f9f 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -136,7 +136,10 @@ def setUp(self): if TestBase.IsDarwin(): # For reducing SSD usage on our physical Mac machines. f.write('common --experimental_repository_cache_hardlinks\n') - f.write('common --enable_bzlmod\n') + if TestBase.IsDarwin(): + # Prefer ipv6 network on macOS + f.write('startup --host_jvm_args=-Djava.net.preferIPv6Addresses=true\n') + f.write('build --jvmopt=-Djava.net.preferIPv6Addresses\n') self.CopyFile( self.Rlocation('io_bazel/src/test/tools/bzlmod/MODULE.bazel.lock'), 'MODULE.bazel.lock', diff --git a/src/test/shell/bazel/testing_server.py b/src/test/shell/bazel/testing_server.py index e4255b46687394..74598fa751e11b 100644 --- a/src/test/shell/bazel/testing_server.py +++ b/src/test/shell/bazel/testing_server.py @@ -41,6 +41,10 @@ import time +class TCPServerV6(TCPServer): + address_family = socket.AF_INET6 + + class Handler(BaseHTTPRequestHandler): """Handlers for testing HTTP server.""" auth = False @@ -152,7 +156,10 @@ def main(argv): while port is None: try: port = random.randrange(32760, 59760) - httpd = TCPServer(('', port), Handler) + if sys.platform == 'darwin': + httpd = TCPServerV6(('', port), Handler) + else: + httpd = TCPServer(('', port), Handler) except socket.error: port = None sys.stdout.write('%d\nstarted\n' % (port,)) diff --git a/src/test/shell/testenv.sh.tmpl b/src/test/shell/testenv.sh.tmpl index 6db1a9997ce196..852c3db720ee47 100755 --- a/src/test/shell/testenv.sh.tmpl +++ b/src/test/shell/testenv.sh.tmpl @@ -341,6 +341,12 @@ EOF echo "testenv.sh: Using shared install base at $TEST_INSTALL_BASE." echo "startup --install_base=$TEST_INSTALL_BASE" >> $TEST_TMPDIR/bazelrc fi + + if is_darwin; then + echo "Add flags to prefer ipv6 network" + echo "startup --host_jvm_args=-Djava.net.preferIPv6Addresses=true" >> $TEST_TMPDIR/bazelrc + echo "build --jvmopt=-Djava.net.preferIPv6Addresses" >> $TEST_TMPDIR/bazelrc + fi } function setup_android_sdk_support() {