Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Poll tests: allow a small amount of spurious wakeups to happen
Browse files Browse the repository at this point in the history
This seems to be unavoidable on windows.
  • Loading branch information
piscisaureus committed May 3, 2012
1 parent d48d256 commit 830d744
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions test/test-poll.c
Expand Up @@ -44,9 +44,11 @@ typedef enum {

static test_mode_t test_mode = DUPLEX;


static int closed_connections = 0;

static int valid_writable_wakeups = 0;
static int spurious_writable_wakeups = 0;


typedef struct connection_context_s {
uv_poll_t poll_handle;
Expand Down Expand Up @@ -289,27 +291,47 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {

int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);

r = send(context->sock, buffer, send_bytes, 0);

if (r < 0) {
ASSERT(got_eagain());
spurious_writable_wakeups++;
break;
}

ASSERT(r > 0);
context->sent += r;
valid_writable_wakeups++;
break;
}

case 2:
case 3: {
/* Send until EAGAIN. */
static char buffer[1234];

/* Send until EAGAIN. */
int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);

r = send(context->sock, buffer, send_bytes, 0);

if (r < 0) {
ASSERT(got_eagain());
spurious_writable_wakeups++;
break;
}

ASSERT(r > 0);
valid_writable_wakeups++;
context->sent += r;

while (context->sent < TRANSFER_BYTES) {
send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);

r = send(context->sock, buffer, send_bytes, 0);

if (r <= 0) break;
context->sent += r;
}
Expand Down Expand Up @@ -511,6 +533,11 @@ static void start_poll_test() {
r = uv_run(uv_default_loop());
ASSERT(r == 0);

/* Assert that at most one percent of the writable wakeups was spurious. */
ASSERT(spurious_writable_wakeups == 0 ||
(valid_writable_wakeups + spurious_writable_wakeups) /
spurious_writable_wakeups > 100);

ASSERT(closed_connections == NUM_CLIENTS * 2);
}

Expand Down

0 comments on commit 830d744

Please sign in to comment.