Skip to content

Commit

Permalink
test: fix test-ipc tests
Browse files Browse the repository at this point in the history
A couple of ipc tests failures where undercover by the previous commit.

- In `ipc-heavy-traffic-deadlock-bug`, `uv_shutdown` can fail with
  `UV_ENOTCONN`. Allow it.
- `ipc_closed_handle` was failing consistently on `Centos6` because the
  first large write was completed in just one syscall. Also, there were
  issues with the lifetime of the `uv_write_t` requests. Refactor the
  test so it passes consistently on `Centos6` while fixing the
  `uv_write_t` issues.

PR-URL: libuv#2108
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
santigimeno committed Jan 15, 2019
1 parent 0c9586a commit 1698be7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/test-ipc-heavy-traffic-deadlock-bug.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void write_cb(uv_write_t* req, int status) {
}

static void shutdown_cb(uv_shutdown_t* req, int status) {
ASSERT(status == 0);
ASSERT(status == 0 || status == UV_ENOTCONN);
uv_close((uv_handle_t*) req->handle, NULL);
}

Expand Down
87 changes: 58 additions & 29 deletions test/test-ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ static int local_conn_accepted;
static int remote_conn_accepted;
static int tcp_server_listening;
static uv_write_t write_req;
static uv_write_t write_req2;
static uv_write_t conn_notify_req;
static int close_cb_called;
static int connection_accepted;
static int tcp_conn_read_cb_called;
static int tcp_conn_write_cb_called;
static int closed_handle_data_read;
static int closed_handle_write;

typedef struct {
uv_connect_t conn_req;
Expand All @@ -54,7 +56,15 @@ typedef struct {

#define CONN_COUNT 100
#define BACKLOG 128
#define LARGE_SIZE 1000000
#define LARGE_SIZE 100000

static uv_buf_t large_buf;
static char buffer[LARGE_SIZE];
static uv_write_t write_reqs[300];
static int write_reqs_completed;

static unsigned int write_until_data_queued(void);
static void send_handle_and_close(void);


static void close_server_conn_cb(uv_handle_t* handle) {
Expand Down Expand Up @@ -574,11 +584,17 @@ static void tcp_connection_write_cb(uv_write_t* req, int status) {
static void closed_handle_large_write_cb(uv_write_t* req, int status) {
ASSERT(status == 0);
ASSERT(closed_handle_data_read = LARGE_SIZE);
if (++write_reqs_completed == ARRAY_SIZE(write_reqs)) {
write_reqs_completed = 0;
if (write_until_data_queued() > 0)
send_handle_and_close();
}
}


static void closed_handle_write_cb(uv_write_t* req, int status) {
ASSERT(status == UV_EBADF);
closed_handle_write = 1;
}


Expand Down Expand Up @@ -689,7 +705,6 @@ int ipc_helper(int listen_after_write) {
* over which a handle will be transmitted.
*/
struct sockaddr_in addr;
uv_write_t write_req;
int r;
uv_buf_t buf;

Expand Down Expand Up @@ -789,26 +804,28 @@ int ipc_helper_tcp_connection(void) {
return 0;
}


int ipc_helper_closed_handle(void) {
static unsigned int write_until_data_queued() {
unsigned int i;
int r;
struct sockaddr_in addr;
uv_write_t write_req;
uv_write_t write_req2;
uv_buf_t buf;
char buffer[LARGE_SIZE];

r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);

uv_pipe_open(&channel, 0);
i = 0;
do {
r = uv_write(&write_reqs[i],
(uv_stream_t*)&channel,
&large_buf,
1,
closed_handle_large_write_cb);
ASSERT(r == 0);
i++;
} while (((uv_stream_t*)&channel)->write_queue_size == 0 &&
i < ARRAY_SIZE(write_reqs));

ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));
return ((uv_stream_t*)&channel)->write_queue_size;
}

memset(buffer, '.', LARGE_SIZE);
buf = uv_buf_init(buffer, LARGE_SIZE);
static void send_handle_and_close() {
int r;
struct sockaddr_in addr;

r = uv_tcp_init(uv_default_loop(), &tcp_server);
ASSERT(r == 0);
Expand All @@ -818,26 +835,40 @@ int ipc_helper_closed_handle(void) {
r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0);
ASSERT(r == 0);

r = uv_write(&write_req,
(uv_stream_t*)&channel,
&buf,
1,
closed_handle_large_write_cb);
ASSERT(r == 0);

r = uv_write2(&write_req2,
r = uv_write2(&write_req,
(uv_stream_t*)&channel,
&buf,
&large_buf,
1,
(uv_stream_t*)&tcp_server,
closed_handle_write_cb);
ASSERT(r == 0);

uv_close((uv_handle_t*)&tcp_server, NULL);
}

int ipc_helper_closed_handle(void) {
int r;

memset(buffer, '.', LARGE_SIZE);
large_buf = uv_buf_init(buffer, LARGE_SIZE);

r = uv_pipe_init(uv_default_loop(), &channel, 1);
ASSERT(r == 0);

uv_pipe_open(&channel, 0);

ASSERT(1 == uv_is_readable((uv_stream_t*) &channel));
ASSERT(1 == uv_is_writable((uv_stream_t*) &channel));
ASSERT(0 == uv_is_closing((uv_handle_t*) &channel));

if (write_until_data_queued() > 0)
send_handle_and_close();

r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0);

ASSERT(closed_handle_write == 1);

MAKE_VALGRIND_HAPPY();
return 0;
}
Expand All @@ -849,8 +880,6 @@ int ipc_helper_bind_twice(void) {
* over which two handles will be transmitted.
*/
struct sockaddr_in addr;
uv_write_t write_req;
uv_write_t write_req2;
int r;
uv_buf_t buf;

Expand Down

0 comments on commit 1698be7

Please sign in to comment.