Skip to content

Commit

Permalink
fix test_worker_stats (ray-project#7655)
Browse files Browse the repository at this point in the history
* fix test_worker_stats

* fix lint error

* fix lint error

Co-authored-by: senlin.zsl <[email protected]>
  • Loading branch information
wumuzi520 and senlin.zsl authored Mar 20, 2020
1 parent e69664b commit 7d08b41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
24 changes: 24 additions & 0 deletions python/ray/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import tempfile
import time
import socket

import ray

Expand Down Expand Up @@ -234,3 +235,26 @@ def put_object(obj, use_ray_put):
return ray.put(obj)
else:
return _put.remote(obj)


def wait_until_server_available(address,
timeout_ms=5000,
retry_interval_ms=100):
ip_port = address.split(":")
ip = ip_port[0]
port = int(ip_port[1])
time_elapsed = 0
start = time.time()
while time_elapsed <= timeout_ms:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((ip, port))
except Exception:
time_elapsed = (time.time() - start) * 1000
time.sleep(retry_interval_ms / 1000.0)
s.close()
continue
s.close()
return True
return False
9 changes: 8 additions & 1 deletion python/ray/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from ray.core.generated import reporter_pb2
from ray.core.generated import reporter_pb2_grpc
from ray.test_utils import (RayTestTimeoutException,
wait_until_succeeded_without_exception)
wait_until_succeeded_without_exception,
wait_until_server_available)

import psutil # We must import psutil after ray because we bundle it with ray.

Expand Down Expand Up @@ -125,6 +126,8 @@ def actor_killed(PID):
else:
return False

assert (wait_until_server_available(addresses["webui_url"]) is True)

webui_url = addresses["webui_url"]
webui_url = webui_url.replace("localhost", "http://127.0.0.1")
for worker in reply.workers_stats:
Expand Down Expand Up @@ -185,6 +188,8 @@ def getpid(self):
c.local_store.remote()
c.remote_store.remote()

assert (wait_until_server_available(addresses["webui_url"]) is True)

start_time = time.time()
while True:
time.sleep(1)
Expand Down Expand Up @@ -267,6 +272,7 @@ def __init__(self):
ActorRequiringGPU.remote()

def test_infeasible_actor(ray_addresses):
assert (wait_until_server_available(addresses["webui_url"]) is True)
webui_url = ray_addresses["webui_url"].replace("localhost",
"http://127.0.0.1")
raylet_info = requests.get(webui_url + "/api/raylet_info").json()
Expand Down Expand Up @@ -306,6 +312,7 @@ def __init__(self):
assert parent_actor is not None

def test_pending_actor(ray_addresses):
assert (wait_until_server_available(addresses["webui_url"]) is True)
webui_url = ray_addresses["webui_url"].replace("localhost",
"http://127.0.0.1")
raylet_info = requests.get(webui_url + "/api/raylet_info").json()
Expand Down

0 comments on commit 7d08b41

Please sign in to comment.