[TEST]Check if port is free before start up redis (#9974)

* [TEST]Check if port is free before start up redis

* per comment
This commit is contained in:
Tao Wang 2020-08-08 01:15:12 +08:00 committed by GitHub
parent 22934619df
commit 8bea875673
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@
#include <functional> #include <functional>
#include "ray/common/buffer.h" #include "ray/common/buffer.h"
#include "ray/common/network_util.h"
#include "ray/common/ray_object.h" #include "ray/common/ray_object.h"
#include "ray/common/test_util.h" #include "ray/common/test_util.h"
#include "ray/util/filesystem.h" #include "ray/util/filesystem.h"
@ -46,7 +47,9 @@ int TestSetupUtil::StartUpRedisServer(const int &port) {
srand(current_time_ms() % RAND_MAX); srand(current_time_ms() % RAND_MAX);
} }
// Use random port (in range [2000, 7000) to avoid port conflicts between UTs. // Use random port (in range [2000, 7000) to avoid port conflicts between UTs.
do {
actual_port = rand() % 5000 + 2000; actual_port = rand() % 5000 + 2000;
} while (!CheckFree(actual_port));
} }
std::string program = TEST_REDIS_SERVER_EXEC_PATH; std::string program = TEST_REDIS_SERVER_EXEC_PATH;