From 8bea87567320f0c6a9c53c3a73990f378908f7b1 Mon Sep 17 00:00:00 2001 From: Tao Wang Date: Sat, 8 Aug 2020 01:15:12 +0800 Subject: [PATCH] [TEST]Check if port is free before start up redis (#9974) * [TEST]Check if port is free before start up redis * per comment --- src/ray/common/test_util.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ray/common/test_util.cc b/src/ray/common/test_util.cc index cbd27c656..d8ceeeec6 100644 --- a/src/ray/common/test_util.cc +++ b/src/ray/common/test_util.cc @@ -18,6 +18,7 @@ #include #include "ray/common/buffer.h" +#include "ray/common/network_util.h" #include "ray/common/ray_object.h" #include "ray/common/test_util.h" #include "ray/util/filesystem.h" @@ -46,7 +47,9 @@ int TestSetupUtil::StartUpRedisServer(const int &port) { srand(current_time_ms() % RAND_MAX); } // Use random port (in range [2000, 7000) to avoid port conflicts between UTs. - actual_port = rand() % 5000 + 2000; + do { + actual_port = rand() % 5000 + 2000; + } while (!CheckFree(actual_port)); } std::string program = TEST_REDIS_SERVER_EXEC_PATH;