From 779b3876f6e7e868de31c71ecc79bca3de916ebd Mon Sep 17 00:00:00 2001 From: fangfengbin <869218239a@zju.edu.cn> Date: Wed, 6 Jan 2021 13:52:39 +0800 Subject: [PATCH] [GCS]Fix TestActorSubscribeAll bug (#13193) --- .../test/service_based_gcs_client_test.cc | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc b/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc index 577f15a0d..521b280d8 100644 --- a/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc +++ b/src/ray/gcs/gcs_client/test/service_based_gcs_client_test.cc @@ -588,6 +588,29 @@ TEST_F(ServiceBasedGcsClientTest, TestJobInfo) { WaitForExpectedCount(job_updates, 2); } +TEST_F(ServiceBasedGcsClientTest, TestActorSubscribeAll) { + // NOTE: `TestActorSubscribeAll` will subscribe to all actor messages, so we need to + // execute it before `TestActorInfo`, otherwise `TestActorSubscribeAll` will receive + // messages from `TestActorInfo`. + // Create actor table data. + JobID job_id = JobID::FromInt(1); + auto actor_table_data1 = Mocker::GenActorTableData(job_id); + auto actor_table_data2 = Mocker::GenActorTableData(job_id); + + // Subscribe to any register or update operations of actors. + std::atomic actor_update_count(0); + auto on_subscribe = [&actor_update_count](const ActorID &actor_id, + const gcs::ActorTableData &data) { + ++actor_update_count; + }; + ASSERT_TRUE(SubscribeAllActors(on_subscribe)); + + // Register an actor to GCS. + RegisterActor(actor_table_data1, false); + RegisterActor(actor_table_data2, false); + WaitForExpectedCount(actor_update_count, 2); +} + TEST_F(ServiceBasedGcsClientTest, TestActorInfo) { // Create actor table data. JobID job_id = JobID::FromInt(1); @@ -611,26 +634,6 @@ TEST_F(ServiceBasedGcsClientTest, TestActorInfo) { WaitForActorUnsubscribed(actor_id); } -TEST_F(ServiceBasedGcsClientTest, TestActorSubscribeAll) { - // Create actor table data. - JobID job_id = JobID::FromInt(1); - auto actor_table_data1 = Mocker::GenActorTableData(job_id); - auto actor_table_data2 = Mocker::GenActorTableData(job_id); - - // Subscribe to any register or update operations of actors. - std::atomic actor_update_count(0); - auto on_subscribe = [&actor_update_count](const ActorID &actor_id, - const gcs::ActorTableData &data) { - ++actor_update_count; - }; - ASSERT_TRUE(SubscribeAllActors(on_subscribe)); - - // Register an actor to GCS. - RegisterActor(actor_table_data1, false); - RegisterActor(actor_table_data2, false); - WaitForExpectedCount(actor_update_count, 2); -} - TEST_F(ServiceBasedGcsClientTest, TestNodeInfo) { // Create gcs node info. auto gcs_node1_info = Mocker::GenNodeInfo();