Skip to content

Commit

Permalink
[Serve] [runtime_env] [CI] Skip flaky Ray Client test (ray-project#26400
Browse files Browse the repository at this point in the history
)
  • Loading branch information
architkulkarni committed Jul 12, 2022
1 parent 92efc85 commit 0914e56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 86 deletions.
74 changes: 21 additions & 53 deletions python/ray/serve/tests/test_runtime_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from ray._private.test_utils import run_string_as_driver


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(sys.platform == "win32", reason="Fail to create temp dir.")
def test_failure_condition(ray_start, tmp_dir, use_ray_client):
def test_failure_condition(ray_start, tmp_dir):
# Verify that the test conditions fail without passing the working dir.
with open("hello", "w") as f:
f.write("world")
Expand All @@ -17,10 +16,7 @@ def test_failure_condition(ray_start, tmp_dir, use_ray_client):
import ray
from ray import serve
if {use_ray_client}:
ray.util.connect("{client_addr}")
else:
ray.init(address="auto")
ray.init(address="auto")
serve.start()
Expand All @@ -36,25 +32,18 @@ def __call__(self, *args):
assert False, "Should not get here"
except FileNotFoundError:
pass
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver)


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(sys.platform == "win32", reason="Fail to create temp dir.")
def test_working_dir_basic(ray_start, tmp_dir, use_ray_client, ray_shutdown):
def test_working_dir_basic(ray_start, tmp_dir, ray_shutdown):
with open("hello", "w") as f:
f.write("world")
print("Wrote file")
if use_ray_client:
ray.init(
f"ray:https://{ray_start}", namespace="serve", runtime_env={"working_dir": "."}
)
else:
ray.init(address="auto", namespace="serve", runtime_env={"working_dir": "."})

ray.init(address="auto", namespace="serve", runtime_env={"working_dir": "."})
print("Initialized Ray")
serve.start()
print("Started Serve")
Expand All @@ -71,21 +60,17 @@ def __call__(self, *args):
assert ray.get(handle.remote()) == "world"


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(sys.platform == "win32", reason="Fail to create temp dir.")
def test_working_dir_connect_from_new_driver(ray_start, tmp_dir, use_ray_client):
def test_working_dir_connect_from_new_driver(ray_start, tmp_dir):
with open("hello", "w") as f:
f.write("world")

driver1 = """
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Expand All @@ -97,38 +82,31 @@ def __call__(self, *args):
Test.deploy()
handle = Test.get_handle()
assert ray.get(handle.remote()) == "world"
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver1)

driver2 = """
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Test = serve.get_deployment("Test")
handle = Test.get_handle()
assert ray.get(handle.remote()) == "world"
Test.delete()
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver2)


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(sys.platform == "win32", reason="Fail to create temp dir.")
def test_working_dir_scale_up_in_new_driver(ray_start, tmp_dir, use_ray_client):
def test_working_dir_scale_up_in_new_driver(ray_start, tmp_dir):
with open("hello", "w") as f:
f.write("world")

Expand All @@ -138,11 +116,8 @@ def test_working_dir_scale_up_in_new_driver(ray_start, tmp_dir, use_ray_client):
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Expand All @@ -154,9 +129,7 @@ def __call__(self, *args):
Test.deploy()
handle = Test.get_handle()
assert ray.get(handle.remote())[1] == "world"
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver1)

Expand All @@ -167,11 +140,8 @@ def __call__(self, *args):
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Expand All @@ -185,9 +155,7 @@ def __call__(self, *args):
assert len(set(r[0] for r in results)) == 2, (
"make sure there are two replicas")
Test.delete()
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver2)

Expand Down
50 changes: 17 additions & 33 deletions python/ray/serve/tests/test_runtime_env_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@
from ray._private.test_utils import run_string_as_driver


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(sys.platform == "win32", reason="Fail to create temp dir.")
def test_working_dir_deploy_new_version(ray_start, tmp_dir, use_ray_client):
def test_working_dir_deploy_new_version(ray_start, tmp_dir):
with open("hello", "w") as f:
f.write("world")

driver1 = """
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Expand All @@ -30,9 +26,7 @@ def __call__(self, *args):
Test.deploy()
handle = Test.get_handle()
assert ray.get(handle.remote()) == "world"
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver1)

Expand All @@ -43,11 +37,8 @@ def __call__(self, *args):
import ray
from ray import serve
job_config = ray.job_config.JobConfig(runtime_env={{"working_dir": "."}})
if {use_ray_client}:
ray.util.connect("{client_addr}", namespace="serve", job_config=job_config)
else:
ray.init(address="auto", namespace="serve", job_config=job_config)
job_config = ray.job_config.JobConfig(runtime_env={"working_dir": "."})
ray.init(address="auto", namespace="serve", job_config=job_config)
serve.start(detached=True)
Expand All @@ -60,28 +51,22 @@ def __call__(self, *args):
handle = Test.get_handle()
assert ray.get(handle.remote()) == "world2"
Test.delete()
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver2)


@pytest.mark.parametrize("use_ray_client", [False, True])
@pytest.mark.skipif(
sys.platform == "win32", reason="Runtime env unsupported on Windows"
)
def test_pip_no_working_dir(ray_start, use_ray_client):
def test_pip_no_working_dir(ray_start):

driver = """
import ray
from ray import serve
import requests
if {use_ray_client}:
ray.util.connect("{client_addr}")
else:
ray.init(address="auto")
ray.init(address="auto")
serve.start()
Expand All @@ -92,18 +77,17 @@ def requests_version(request):
requests_version.options(
ray_actor_options={{
"runtime_env": {{
"pip": ["ray[serve]", "requests==2.25.1"]
}}
}}).deploy()
ray_actor_options={
"runtime_env": {
"pip": ["requests==2.25.1"]
}
}).deploy()
assert requests.get("http:https://127.0.0.1:8000/requests_version").text == "2.25.1"
""".format(
use_ray_client=use_ray_client, client_addr=ray_start
)
"""

run_string_as_driver(driver)
output = run_string_as_driver(driver)
print(output)


if __name__ == "__main__":
Expand Down

0 comments on commit 0914e56

Please sign in to comment.