Skip to content

Commit

Permalink
Prefer ipv6 network in integration tests on macOS
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 592595418
Change-Id: I59bfb00ea1ddbea121e32f38453c6055b7a38ad9
  • Loading branch information
meteorcloudy authored and copybara-github committed Dec 20, 2023
1 parent 9810870 commit 2c51a0c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 10 additions & 1 deletion src/test/py/bazel/remote/cache_decompression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 8 additions & 1 deletion src/test/shell/bazel/testing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
import time


class TCPServerV6(TCPServer):
address_family = socket.AF_INET6


class Handler(BaseHTTPRequestHandler):
"""Handlers for testing HTTP server."""
auth = False
Expand Down Expand Up @@ -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,))
Expand Down
6 changes: 6 additions & 0 deletions src/test/shell/testenv.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2c51a0c

Please sign in to comment.