diff --git a/python/ray/state.py b/python/ray/state.py index 00622f3b2..453530bbf 100644 --- a/python/ray/state.py +++ b/python/ray/state.py @@ -318,9 +318,9 @@ class GlobalState: return {} gcs_entries = gcs_utils.GcsEntry.FromString(message) - assert len(gcs_entries.entries) == 1 + assert len(gcs_entries.entries) > 0 actor_table_data = gcs_utils.ActorTableData.FromString( - gcs_entries.entries[0]) + gcs_entries.entries[-1]) actor_info = { "ActorID": binary_to_hex(actor_table_data.actor_id), diff --git a/python/ray/tests/test_global_state.py b/python/ray/tests/test_global_state.py index b93e3067b..b5ac072a2 100644 --- a/python/ray/tests/test_global_state.py +++ b/python/ray/tests/test_global_state.py @@ -76,6 +76,36 @@ def test_add_remove_cluster_resources(ray_start_cluster_head): assert ray.cluster_resources()["CPU"] == 6 +def test_global_state_actor_table(ray_start_regular): + @ray.remote + class Actor: + def ready(self): + pass + + # actor table should be empty at first + assert len(ray.actors()) == 0 + + # actor table should contain only one entry + a = Actor.remote() + ray.get(a.ready.remote()) + assert len(ray.actors()) == 1 + + # actor table should contain only this entry + # even when the actor goes out of scope + del a + + def get_state(): + return list(ray.actors().values())[0]["State"] + + dead_state = ray.gcs_utils.ActorTableData.DEAD + for _ in range(10): + if get_state() == dead_state: + break + else: + time.sleep(0.5) + assert get_state() == dead_state + + if __name__ == "__main__": import pytest import sys