Skip to content

Commit

Permalink
[gcs] Make core worker test compilable. (ray-project#23608)
Browse files Browse the repository at this point in the history
It seems like core worker test is not running and it breaks the build. This PR fixed this.
  • Loading branch information
fishbone authored Mar 31, 2022
1 parent 944e8e1 commit d01f947
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 45 deletions.
40 changes: 21 additions & 19 deletions src/ray/common/test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ void TestSetupUtil::FlushRedisServer(const int &port) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

std::string TestSetupUtil::StartGcsServer(const std::string &redis_address) {
std::string TestSetupUtil::StartGcsServer(int port) {
std::string gcs_server_socket_name =
ray::JoinPaths(ray::GetUserTempDir(), "gcs_server" + ObjectID::FromRandom().Hex());
std::vector<std::string> cmdargs(
{TEST_GCS_SERVER_EXEC_PATH,
"--redis_address=" + redis_address,
"--gcs_server_port=" + std::to_string(port),
"--config_list=" +
absl::Base64Escape(R"({"object_timeout_milliseconds": 2000})")});
cmdargs.push_back("--gcs_server_port=6379");
Expand All @@ -125,25 +125,27 @@ std::string TestSetupUtil::StartRaylet(const std::string &node_ip_address,
ray::JoinPaths(ray::GetUserTempDir(), "raylet" + ObjectID::FromRandom().Hex());
std::string plasma_store_socket_name =
ray::JoinPaths(ray::GetUserTempDir(), "store" + ObjectID::FromRandom().Hex());
std::vector<std::string> cmdargs(
{TEST_RAYLET_EXEC_PATH,
"--raylet_socket_name=" + raylet_socket_name,
"--store_socket_name=" + plasma_store_socket_name,
"--object_manager_port=0",
"--node_manager_port=" + std::to_string(port),
"--node_ip_address=" + node_ip_address,
"--redis_port=6379",
"--min-worker-port=0",
"--max-worker-port=0",
"--maximum_startup_concurrency=10",
"--static_resource_list=" + resource,
"--python_worker_command=" + CreateCommandLine({TEST_MOCK_WORKER_EXEC_PATH,
std::string mock_worker_command = CreateCommandLine({TEST_MOCK_WORKER_EXEC_PATH,
plasma_store_socket_name,
raylet_socket_name,
std::to_string(port)}),
"--object_store_memory=10000000"});
cmdargs.push_back("--gcs-address=" + bootstrap_address);
RAY_LOG(DEBUG) << "Raylet Start command: " << CreateCommandLine(cmdargs);
std::to_string(port),
""});
RAY_LOG(INFO) << "MockWorkerCommand: " << mock_worker_command;
std::vector<std::string> cmdargs({TEST_RAYLET_EXEC_PATH,
"--raylet_socket_name=" + raylet_socket_name,
"--gcs-address=" + bootstrap_address,
"--store_socket_name=" + plasma_store_socket_name,
"--object_manager_port=0",
"--node_manager_port=" + std::to_string(port),
"--node_ip_address=" + node_ip_address,
"--min-worker-port=0",
"--max-worker-port=0",
"--maximum_startup_concurrency=10",
"--static_resource_list=" + resource,
"--python_worker_command=" + mock_worker_command,
"--object_store_memory=10000000"});

RAY_LOG(INFO) << "Raylet Start command: " << CreateCommandLine(cmdargs);
RAY_CHECK(!Process::Spawn(cmdargs, true, raylet_socket_name + ".pid").second);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
*store_socket_name = plasma_store_socket_name;
Expand Down
2 changes: 1 addition & 1 deletion src/ray/common/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TestSetupUtil {
static void ShutDownRedisServers();
static void FlushAllRedisServers();

static std::string StartGcsServer(const std::string &redis_address);
static std::string StartGcsServer(int port);
static void StopGcsServer(const std::string &gcs_server_socket_name);
static std::string StartRaylet(const std::string &node_ip_address,
const int &port,
Expand Down
26 changes: 3 additions & 23 deletions src/ray/core_worker/test/core_worker_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "absl/container/flat_hash_set.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "hiredis/async.h"
#include "hiredis/hiredis.h"
#include "ray/common/buffer.h"
#include "ray/common/common_protocol.h"
#include "ray/common/ray_object.h"
Expand All @@ -48,14 +46,6 @@ int node_manager_port = 0;
namespace ray {
namespace core {

static void flushall_redis(void) {
redisContext *context = redisConnect("127.0.0.1", 6379);
freeReplyObject(redisCommand(context, "FLUSHALL"));
freeReplyObject(redisCommand(context, "SET NumRedisShards 1"));
freeReplyObject(redisCommand(context, "LPUSH RedisShards 127.0.0.1:6380"));
redisFree(context);
}

ActorID CreateActorHelper(std::unordered_map<std::string, double> &resources,
int64_t max_restarts) {
uint8_t array[] = {1, 2, 3};
Expand Down Expand Up @@ -98,29 +88,23 @@ std::string MetadataToString(std::shared_ptr<RayObject> obj) {

class CoreWorkerTest : public ::testing::Test {
public:
CoreWorkerTest(int num_nodes)
: num_nodes_(num_nodes), gcs_options_("127.0.0.1", 6379, "") {
TestSetupUtil::StartUpRedisServers(std::vector<int>{6379, 6380});

// flush redis first.
flushall_redis();

CoreWorkerTest(int num_nodes) : num_nodes_(num_nodes), gcs_options_("127.0.0.1:6379") {
RAY_CHECK(num_nodes >= 0);
if (num_nodes > 0) {
raylet_socket_names_.resize(num_nodes);
raylet_store_socket_names_.resize(num_nodes);
}

// start gcs server
gcs_server_socket_name_ = TestSetupUtil::StartGcsServer("127.0.0.1");
gcs_server_socket_name_ = TestSetupUtil::StartGcsServer(6379);

// start raylet on each node. Assign each node with different resources so that
// a task can be scheduled to the desired node.
for (int i = 0; i < num_nodes; i++) {
raylet_socket_names_[i] =
TestSetupUtil::StartRaylet("127.0.0.1",
node_manager_port + i,
"127.0.0.1",
"127.0.0.1:6379",
"\"CPU,4.0,resource" + std::to_string(i) + ",10\"",
&raylet_store_socket_names_[i]);
}
Expand All @@ -134,8 +118,6 @@ class CoreWorkerTest : public ::testing::Test {
if (!gcs_server_socket_name_.empty()) {
TestSetupUtil::StopGcsServer(gcs_server_socket_name_);
}

TestSetupUtil::ShutDownRedisServers();
}

JobID NextJobId() const {
Expand Down Expand Up @@ -1130,7 +1112,5 @@ int main(int argc, char **argv) {
ray::TEST_MOCK_WORKER_EXEC_PATH = std::string(argv[2]);
ray::TEST_GCS_SERVER_EXEC_PATH = std::string(argv[3]);

ray::TEST_REDIS_CLIENT_EXEC_PATH = std::string(argv[4]);
ray::TEST_REDIS_SERVER_EXEC_PATH = std::string(argv[5]);
return RUN_ALL_TESTS();
}
4 changes: 2 additions & 2 deletions src/ray/core_worker/test/mock_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ class MockWorker {
} // namespace ray

int main(int argc, char **argv) {
RAY_CHECK(argc >= 4);
RAY_CHECK(argc >= 5);
auto store_socket = std::string(argv[1]);
auto raylet_socket = std::string(argv[2]);
auto node_manager_port = std::stoi(std::string(argv[3]));
auto startup_token_str = std::string(argv[4]);
auto start = startup_token_str.find(std::string("=")) + 1;
auto startup_token = std::stoi(startup_token_str.substr(start));

ray::gcs::GcsClientOptions gcs_options("127.0.0.1", 6379, "");
ray::gcs::GcsClientOptions gcs_options("127.0.0.1:6379");
ray::core::MockWorker worker(
store_socket, raylet_socket, node_manager_port, gcs_options, startup_token);
worker.RunTaskExecutionLoop();
Expand Down

0 comments on commit d01f947

Please sign in to comment.