[ClientBuilder] Code takes precedence over environment (#16112)

* no override address

* correct ordering
This commit is contained in:
Ian Rodney 2021-06-02 03:10:15 -07:00 committed by GitHub
parent f14f197d42
commit 2e365f8797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 6 deletions

View file

@ -166,11 +166,11 @@ def client(address: Optional[str] = None) -> ClientBuilder:
* ``"module://inner_address"``: load module.ClientBuilder & pass * ``"module://inner_address"``: load module.ClientBuilder & pass
inner_address inner_address
""" """
override_address = os.environ.get(RAY_ADDRESS_ENVIRONMENT_VARIABLE) env_address = os.environ.get(RAY_ADDRESS_ENVIRONMENT_VARIABLE)
if override_address: if env_address and address is None:
logger.debug( logger.debug(
f"Using address ({override_address}) instead of " f"Using address ({env_address}) instead of auto-detection "
f"({address}) because {RAY_ADDRESS_ENVIRONMENT_VARIABLE} is set") f"because {RAY_ADDRESS_ENVIRONMENT_VARIABLE} is set.")
address = override_address address = env_address
return _get_builder_from_address(address) return _get_builder_from_address(address)

View file

@ -1,3 +1,4 @@
import os
import pytest import pytest
import subprocess import subprocess
import sys import sys
@ -210,6 +211,27 @@ def test_disconnect(call_ray_stop_only):
ctx.disconnect() ctx.disconnect()
# Check idempotency # Check idempotency
ctx.disconnect() ctx.disconnect()
with pytest.raises(ray.exceptions.RaySystemError): with pytest.raises(ray.exceptions.RaySystemError):
ray.put(300) ray.put(300)
def test_address_resolution(ray_start_regular_shared):
server = ray_client_server.serve("localhost:50055")
with ray.client("localhost:50055").connect():
assert ray.util.client.ray.is_connected()
try:
os.environ["RAY_ADDRESS"] = "local"
with ray.client("localhost:50055").connect():
# client(...) takes precedence of RAY_ADDRESS=local
assert ray.util.client.ray.is_connected()
ray.client(None).connect()
assert ray.worker.global_worker.node.is_head()
finally:
if os.environ["RAY_ADDRESS"]:
del os.environ["RAY_ADDRESS"]
server.stop(0)
subprocess.check_output("ray stop --force", shell=True)