Skip to content

Commit

Permalink
tls: Make test failures more useful
Browse files Browse the repository at this point in the history
test-tls-server often fails with

    recv_reply: assertion failed (len >= 100): (-1 >= 100)

which is not particularly enlightening. It could be something simple
like EINTR, or the timeout loop actually running all the way to the end
without ever getting an actual response. Make the failure of both of
them more explicit and verbose, and also print errors.
  • Loading branch information
martinpitt authored and allisonkarlitskaya committed Feb 14, 2023
1 parent ad55122 commit 5d5ae70
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tls/test-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ recv_reply (int fd, char *buf, size_t buflen)

len = recv (fd, buf, buflen - 1, MSG_DONTWAIT);
close (fd);
if (len < 0)
g_error ("recv_reply: unexpected error: %m");
g_assert_cmpint (len, >=, 100);
buf[len] = '\0'; /* so that we can use string functions on it */

Expand All @@ -192,13 +194,19 @@ do_request (TestCase *tc, const char *request)
{
static char buf[4096];
int fd = do_connect (tc);
int res;

send_request (fd, request);
/* wait until data is available */
for (int timeout = 0; timeout < 100 && recv (fd, buf, 100, MSG_PEEK | MSG_DONTWAIT) < 100; ++timeout)
for (int timeout = 0; timeout < 100; ++timeout) {
res = recv (fd, buf, 100, MSG_PEEK | MSG_DONTWAIT);
if (res >= 100)
return recv_reply (fd, buf, sizeof (buf));

server_poll_event (100);
}

return recv_reply (fd, buf, sizeof (buf));
g_error ("timed out waiting for enough data to become available: res=%d, error: %m", res);
}

static void
Expand Down

0 comments on commit 5d5ae70

Please sign in to comment.