mirror of
https://github.com/wassname/ray.git
synced 2026-06-30 03:30:12 +08:00
Make more tests compatible with Windows (#9303)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import os
|
||||
import pytest
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import ray
|
||||
from ray.test_utils import (
|
||||
RayTestTimeoutException, run_string_as_driver,
|
||||
RayTestTimeoutException, check_call_ray, run_string_as_driver,
|
||||
run_string_as_driver_nonblocking, wait_for_children_of_pid,
|
||||
wait_for_children_of_pid_to_exit, kill_process_by_name, Semaphore)
|
||||
|
||||
@@ -357,66 +358,62 @@ def test_calling_start_ray_head(call_ray_stop_only):
|
||||
# should also test the non-head node code path.
|
||||
|
||||
# Test starting Ray with no arguments.
|
||||
subprocess.check_call(["ray", "start", "--head"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with a redis port specified.
|
||||
subprocess.check_call(["ray", "start", "--head"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with a node IP address specified.
|
||||
subprocess.check_call(
|
||||
["ray", "start", "--head", "--node-ip-address", "127.0.0.1"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head", "--node-ip-address", "127.0.0.1"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with the object manager and node manager ports
|
||||
# specified.
|
||||
subprocess.check_call([
|
||||
"ray", "start", "--head", "--object-manager-port", "12345",
|
||||
check_call_ray([
|
||||
"start", "--head", "--object-manager-port", "12345",
|
||||
"--node-manager-port", "54321"
|
||||
])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with the worker port range specified.
|
||||
subprocess.check_call([
|
||||
"ray", "start", "--head", "--min-worker-port", "50000",
|
||||
"--max-worker-port", "51000"
|
||||
check_call_ray([
|
||||
"start", "--head", "--min-worker-port", "50000", "--max-worker-port",
|
||||
"51000"
|
||||
])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with the number of CPUs specified.
|
||||
subprocess.check_call(["ray", "start", "--head", "--num-cpus", "2"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head", "--num-cpus", "2"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with the number of GPUs specified.
|
||||
subprocess.check_call(["ray", "start", "--head", "--num-gpus", "100"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head", "--num-gpus", "100"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with the max redis clients specified.
|
||||
subprocess.check_call(
|
||||
["ray", "start", "--head", "--redis-max-clients", "100"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head", "--redis-max-clients", "100"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
if "RAY_USE_NEW_GCS" not in os.environ:
|
||||
# Test starting Ray with redis shard ports specified.
|
||||
subprocess.check_call([
|
||||
"ray", "start", "--head", "--redis-shard-ports", "6380,6381,6382"
|
||||
])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(
|
||||
["start", "--head", "--redis-shard-ports", "6380,6381,6382"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with all arguments specified.
|
||||
subprocess.check_call([
|
||||
"ray", "start", "--head", "--redis-shard-ports", "6380,6381,6382",
|
||||
check_call_ray([
|
||||
"start", "--head", "--redis-shard-ports", "6380,6381,6382",
|
||||
"--object-manager-port", "12345", "--num-cpus", "2", "--num-gpus",
|
||||
"0", "--redis-max-clients", "100", "--resources", "{\"Custom\": 1}"
|
||||
])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test starting Ray with invalid arguments.
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
subprocess.check_call(
|
||||
["ray", "start", "--head", "--address", "127.0.0.1:6379"])
|
||||
subprocess.check_call(["ray", "stop"])
|
||||
check_call_ray(["start", "--head", "--address", "127.0.0.1:6379"])
|
||||
check_call_ray(["stop"])
|
||||
|
||||
# Test --block. Killing a child process should cause the command to exit.
|
||||
blocked = subprocess.Popen(["ray", "start", "--head", "--block"])
|
||||
@@ -694,18 +691,22 @@ ray.get(main_wait.release.remote())
|
||||
ray.get(main_wait.acquire.remote())
|
||||
ray.get(main_wait.acquire.remote())
|
||||
|
||||
driver1_out = p1.stdout.read().decode("ascii").split("\n")
|
||||
driver2_out = p2.stdout.read().decode("ascii").split("\n")
|
||||
driver1_out = p1.stdout.read().decode("ascii")
|
||||
driver2_out = p2.stdout.read().decode("ascii")
|
||||
if sys.platform == "win32":
|
||||
driver1_out = driver1_out.replace("\r", "")
|
||||
driver2_out = driver2_out.replace("\r", "")
|
||||
driver1_out_split = driver1_out.split("\n")
|
||||
driver2_out_split = driver2_out.split("\n")
|
||||
|
||||
assert driver1_out[0][-1] == "1"
|
||||
assert driver1_out[1][-1] == "2"
|
||||
assert driver2_out[0][-1] == "3"
|
||||
assert driver2_out[1][-1] == "4"
|
||||
assert driver1_out_split[0][-1] == "1"
|
||||
assert driver1_out_split[1][-1] == "2"
|
||||
assert driver2_out_split[0][-1] == "3"
|
||||
assert driver2_out_split[1][-1] == "4"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pytest
|
||||
import sys
|
||||
# Make subprocess happy in bazel.
|
||||
os.environ["LC_ALL"] = "en_US.UTF-8"
|
||||
os.environ["LANG"] = "en_US.UTF-8"
|
||||
|
||||
Reference in New Issue
Block a user