Wait until data is ready to read in manager_tests. (#13)

* Wait until data is ready to read in manager_tests.

* remove race conditions from plasma manager test and make CHECK and CHECKM print a backgrace
This commit is contained in:
Robert Nishihara
2016-10-29 19:25:43 -07:00
committed by GitHub
parent e6319986ec
commit a0049ffa48
2 changed files with 25 additions and 13 deletions
+11 -13
View File
@@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <execinfo.h>
#ifndef RAY_COMMON_DEBUG #ifndef RAY_COMMON_DEBUG
#define LOG_DEBUG(M, ...) #define LOG_DEBUG(M, ...)
@@ -21,21 +22,18 @@
#define LOG_INFO(M, ...) \ #define LOG_INFO(M, ...) \
fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define CHECK(COND) \ #define CHECKM(COND, M, ...) \
do { \ do { \
if (!(COND)) { \ if (!(COND)) { \
LOG_ERR("Check failure: %s", #COND); \ LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \
exit(-1); \ void *buffer[255]; \
} \ const int calls = backtrace(buffer, sizeof(buffer) / sizeof(void *)); \
backtrace_symbols_fd(buffer, calls, 1); \
exit(-1); \
} \
} while (0); } while (0);
#define CHECKM(COND, M, ...) \ #define CHECK(COND) CHECKM(COND, "")
do { \
if (!(COND)) { \
LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \
exit(-1); \
} \
} while (0);
/** This macro indicates that this pointer owns the data it is pointing to /** This macro indicates that this pointer owns the data it is pointing to
* and is responsible for freeing it. */ * and is responsible for freeing it. */
+14
View File
@@ -2,6 +2,7 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <poll.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -21,6 +22,14 @@ const char *store_socket_name = "/tmp/store12345";
const char *manager_socket_name = "/tmp/manager12345"; const char *manager_socket_name = "/tmp/manager12345";
object_id oid; 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) { int test_done_handler(event_loop *loop, timer_id id, void *context) {
event_loop_stop(loop); event_loop_stop(loop);
return AE_NOMORE; return AE_NOMORE;
@@ -59,6 +68,7 @@ plasma_mock *init_plasma_mock(int port, plasma_mock *remote_mock) {
if (remote_mock != NULL) { if (remote_mock != NULL) {
mock->write_conn = mock->write_conn =
get_manager_connection(remote_mock->state, manager_addr, port); 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->read_conn = new_client_connection(mock->loop, mock->manager_remote_fd,
mock->state, 0); mock->state, 0);
} else { } else {
@@ -68,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 /* Connect a new client to the local plasma manager and mock a request to an
* object. */ * object. */
mock->plasma_conn = plasma_connect(store_socket_name, manager_socket_name); mock->plasma_conn = plasma_connect(store_socket_name, manager_socket_name);
wait_for_pollin(mock->manager_local_fd);
mock->client_conn = mock->client_conn =
new_client_connection(mock->loop, mock->manager_local_fd, mock->state, 0); new_client_connection(mock->loop, mock->manager_local_fd, mock->state, 0);
return mock; return mock;
@@ -229,6 +240,9 @@ TEST read_write_object_chunk_test(void) {
* - Check that the data matches. * - Check that the data matches.
*/ */
write_object_chunk(remote_mock->write_conn, &remote_buf); write_object_chunk(remote_mock->write_conn, &remote_buf);
/* Wait until the data is ready to be read. */
wait_for_pollin(get_client_sock(remote_mock->read_conn));
/* Read the data. */
int done = read_object_chunk(remote_mock->read_conn, &local_buf); int done = read_object_chunk(remote_mock->read_conn, &local_buf);
ASSERT(done); ASSERT(done);
ASSERT_EQ(memcmp(remote_buf.data, local_buf.data, data_size), 0); ASSERT_EQ(memcmp(remote_buf.data, local_buf.data, data_size), 0);