mirror of
https://github.com/wassname/ray.git
synced 2026-09-11 12:43:20 +08:00
Fix socket bind collisions in manager_tests, race condition bind/listen/subscribe and memory leaks (#18)
* Fix socket bind collisions in manager_tests * bind manager sockets before connecting to the store * fix memory leak in tests * fix valgrind early process termination * fix bind/listen/subscribe race condition * fix photon * fix other tests * make it that all of common is tested * fix clang-format * fix
This commit is contained in:
committed by
Robert Nishihara
parent
d56c1a0b9c
commit
2068587af8
@@ -5,7 +5,7 @@
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "event_loop.h"
|
||||
#include "test/example_task.h"
|
||||
#include "test_common.h"
|
||||
#include "state/db.h"
|
||||
#include "state/object_table.h"
|
||||
#include "state/task_log.h"
|
||||
@@ -197,13 +197,10 @@ TEST unique_client_id_test(void) {
|
||||
}
|
||||
|
||||
SUITE(db_tests) {
|
||||
redisContext *context = redisConnect("127.0.0.1", 6379);
|
||||
freeReplyObject(redisCommand(context, "FLUSHALL"));
|
||||
RUN_REDIS_TEST(context, object_table_lookup_test);
|
||||
RUN_REDIS_TEST(context, task_log_test);
|
||||
RUN_REDIS_TEST(context, task_log_all_test);
|
||||
RUN_REDIS_TEST(context, unique_client_id_test);
|
||||
redisFree(context);
|
||||
RUN_REDIS_TEST(object_table_lookup_test);
|
||||
RUN_REDIS_TEST(task_log_test);
|
||||
RUN_REDIS_TEST(task_log_all_test);
|
||||
RUN_REDIS_TEST(unique_client_id_test);
|
||||
}
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
@@ -11,7 +11,7 @@ SUITE(io_tests);
|
||||
|
||||
TEST ipc_socket_test(void) {
|
||||
const char *socket_pathname = "test-socket";
|
||||
int socket_fd = bind_ipc_sock(socket_pathname);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname, true);
|
||||
ASSERT(socket_fd >= 0);
|
||||
|
||||
char *test_string = "hello world";
|
||||
@@ -50,7 +50,7 @@ TEST ipc_socket_test(void) {
|
||||
|
||||
TEST long_ipc_socket_test(void) {
|
||||
const char *socket_pathname = "long-test-socket";
|
||||
int socket_fd = bind_ipc_sock(socket_pathname);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname, true);
|
||||
ASSERT(socket_fd >= 0);
|
||||
|
||||
UT_string *test_string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "greatest.h"
|
||||
|
||||
#include "event_loop.h"
|
||||
#include "example_task.h"
|
||||
#include "test_common.h"
|
||||
#include "common.h"
|
||||
#include "state/object_table.h"
|
||||
#include "state/redis.h"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "state/redis.h"
|
||||
#include "io.h"
|
||||
#include "logging.h"
|
||||
#include "test_common.h"
|
||||
|
||||
SUITE(redis_tests);
|
||||
|
||||
@@ -40,7 +41,7 @@ TEST redis_socket_test(void) {
|
||||
const char *socket_pathname = "redis-test-socket";
|
||||
redisContext *context = redisConnect("127.0.0.1", 6379);
|
||||
ASSERT(context != NULL);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname, true);
|
||||
ASSERT(socket_fd >= 0);
|
||||
|
||||
int client_fd = connect_ipc_sock(socket_pathname);
|
||||
@@ -97,7 +98,7 @@ TEST async_redis_socket_test(void) {
|
||||
|
||||
/* Start IPC channel. */
|
||||
const char *socket_pathname = "async-redis-test-socket";
|
||||
int socket_fd = bind_ipc_sock(socket_pathname);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname, true);
|
||||
ASSERT(socket_fd >= 0);
|
||||
utarray_push_back(connections, &socket_fd);
|
||||
|
||||
@@ -171,7 +172,7 @@ TEST logging_test(void) {
|
||||
|
||||
/* Start IPC channel. */
|
||||
const char *socket_pathname = "logging-test-socket";
|
||||
int socket_fd = bind_ipc_sock(socket_pathname);
|
||||
int socket_fd = bind_ipc_sock(socket_pathname, true);
|
||||
ASSERT(socket_fd >= 0);
|
||||
utarray_push_back(connections, &socket_fd);
|
||||
|
||||
@@ -208,12 +209,9 @@ TEST logging_test(void) {
|
||||
}
|
||||
|
||||
SUITE(redis_tests) {
|
||||
redisContext *context = redisConnect("127.0.0.1", 6379);
|
||||
freeReplyObject(redisCommand(context, "FLUSHALL"));
|
||||
RUN_REDIS_TEST(context, redis_socket_test);
|
||||
RUN_REDIS_TEST(context, async_redis_socket_test);
|
||||
RUN_REDIS_TEST(context, logging_test);
|
||||
redisFree(context);
|
||||
RUN_REDIS_TEST(redis_socket_test);
|
||||
RUN_REDIS_TEST(async_redis_socket_test);
|
||||
RUN_REDIS_TEST(logging_test);
|
||||
}
|
||||
|
||||
GREATEST_MAIN_DEFS();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "greatest.h"
|
||||
|
||||
#include "event_loop.h"
|
||||
#include "example_task.h"
|
||||
#include "test_common.h"
|
||||
#include "common.h"
|
||||
#include "state/object_table.h"
|
||||
#include "state/redis.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "test/example_task.h"
|
||||
#include "test_common.h"
|
||||
#include "task.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifndef EXAMPLE_TASK_H
|
||||
#define EXAMPLE_TASK_H
|
||||
#ifndef TEST_COMMON_H
|
||||
#define TEST_COMMON_H
|
||||
|
||||
#include "hiredis/hiredis.h"
|
||||
|
||||
#include "task.h"
|
||||
|
||||
@@ -20,4 +22,18 @@ task_instance *example_task_instance(void) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* Flush redis. */
|
||||
void flushall_redis() {
|
||||
redisContext *context = redisConnect("127.0.0.1", 6379);
|
||||
freeReplyObject(redisCommand(context, "FLUSHALL"));
|
||||
redisFree(context);
|
||||
}
|
||||
|
||||
/* Cleanup method for running tests with the greatest library.
|
||||
* Runs the test, then clears the Redis database. */
|
||||
#define RUN_REDIS_TEST(test) \
|
||||
flushall_redis(); \
|
||||
RUN_TEST(test); \
|
||||
flushall_redis();
|
||||
|
||||
#endif /* TEST_COMMON */
|
||||
Reference in New Issue
Block a user