From 97039d770c80474fa6ac7e07fcff190482bf8746 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Sat, 29 Oct 2016 17:26:59 -0700 Subject: [PATCH 1/2] Wait until data is ready to read in manager_tests. --- src/plasma/test/manager_tests.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/plasma/test/manager_tests.c b/src/plasma/test/manager_tests.c index 0babf7e9bac3..876d12e9ba19 100644 --- a/src/plasma/test/manager_tests.c +++ b/src/plasma/test/manager_tests.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -228,6 +229,13 @@ TEST read_write_object_chunk_test(void) { * - Check that the data matches. */ write_object_chunk(remote_mock->write_conn, &remote_buf); + /* Wait until the data is ready to be read. */ + struct pollfd poll_list[1]; + poll_list[0].fd = get_client_sock(remote_mock->read_conn); + poll_list[0].events = POLLIN; + int retval = poll(poll_list, (unsigned long) 1, -1); + ASSERT(retval > 0); + /* Read the data. */ int done = read_object_chunk(remote_mock->read_conn, &local_buf); ASSERT(done); ASSERT_EQ(memcmp(remote_buf.data, local_buf.data, data_size), 0); From a76f509f6268d2bfd8a3fa2d246c492e07f96d87 Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Sat, 29 Oct 2016 18:38:59 -0700 Subject: [PATCH 2/2] remove race conditions from plasma manager test and make CHECK and CHECKM print a backgrace --- src/common/common.h | 24 +++++++++++------------- src/plasma/test/manager_tests.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/common/common.h b/src/common/common.h index 1a05f89240a5..dada96b247e5 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -6,6 +6,7 @@ #include #include #include +#include #ifndef RAY_COMMON_DEBUG #define LOG_DEBUG(M, ...) @@ -21,21 +22,18 @@ #define LOG_INFO(M, ...) \ fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) -#define CHECK(COND) \ - do { \ - if (!(COND)) { \ - LOG_ERR("Check failure: %s", #COND); \ - exit(-1); \ - } \ +#define CHECKM(COND, M, ...) \ + do { \ + if (!(COND)) { \ + LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \ + void *buffer[255]; \ + const int calls = backtrace(buffer, sizeof(buffer) / sizeof(void *)); \ + backtrace_symbols_fd(buffer, calls, 1); \ + exit(-1); \ + } \ } while (0); -#define CHECKM(COND, M, ...) \ - do { \ - if (!(COND)) { \ - LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \ - exit(-1); \ - } \ - } while (0); +#define CHECK(COND) CHECKM(COND, "") /** This macro indicates that this pointer owns the data it is pointing to * and is responsible for freeing it. */ diff --git a/src/plasma/test/manager_tests.c b/src/plasma/test/manager_tests.c index 876d12e9ba19..6f4a0233214a 100644 --- a/src/plasma/test/manager_tests.c +++ b/src/plasma/test/manager_tests.c @@ -22,6 +22,14 @@ const char *store_socket_name = "/tmp/store12345"; const char *manager_socket_name = "/tmp/manager12345"; object_id oid; +void wait_for_pollin(int fd) { + struct pollfd poll_list[1]; + poll_list[0].fd = fd; + poll_list[0].events = POLLIN; + int retval = poll(poll_list, (unsigned long) 1, -1); + CHECK(retval > 0); +} + int test_done_handler(event_loop *loop, timer_id id, void *context) { event_loop_stop(loop); return AE_NOMORE; @@ -60,6 +68,7 @@ plasma_mock *init_plasma_mock(int port, plasma_mock *remote_mock) { if (remote_mock != NULL) { mock->write_conn = get_manager_connection(remote_mock->state, manager_addr, port); + wait_for_pollin(mock->manager_remote_fd); mock->read_conn = new_client_connection(mock->loop, mock->manager_remote_fd, mock->state, 0); } else { @@ -69,6 +78,7 @@ plasma_mock *init_plasma_mock(int port, plasma_mock *remote_mock) { /* Connect a new client to the local plasma manager and mock a request to an * object. */ mock->plasma_conn = plasma_connect(store_socket_name, manager_socket_name); + wait_for_pollin(mock->manager_local_fd); mock->client_conn = new_client_connection(mock->loop, mock->manager_local_fd, mock->state, 0); return mock; @@ -230,11 +240,7 @@ TEST read_write_object_chunk_test(void) { */ write_object_chunk(remote_mock->write_conn, &remote_buf); /* Wait until the data is ready to be read. */ - struct pollfd poll_list[1]; - poll_list[0].fd = get_client_sock(remote_mock->read_conn); - poll_list[0].events = POLLIN; - int retval = poll(poll_list, (unsigned long) 1, -1); - ASSERT(retval > 0); + wait_for_pollin(get_client_sock(remote_mock->read_conn)); /* Read the data. */ int done = read_object_chunk(remote_mock->read_conn, &local_buf); ASSERT(done);