Skip to content

Commit

Permalink
* test/request.c (status, status_chunked): Revert r1910. Expect hostn…
Browse files Browse the repository at this point in the history
…ame of

  127.0.0.1.

* test/utils.c (session_server, sessi
  • Loading branch information
notroj committed Jul 31, 2013
1 parent fb82d35 commit eff6521
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 91 deletions.
143 changes: 54 additions & 89 deletions test/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,70 +2067,24 @@ static void status_cb(void *userdata, ne_session_status status,
}
}

static void print_addr(char *buf, size_t buflen, const char *recvs,
const ne_inet_addr *i1, const ne_inet_addr *i2)
{
char a1[64], a2[64];

if (i2 == NULL)
ne_snprintf(buf, buflen,
"lookup(localhost)-"
"connecting(localhost,%s)-"
"connected(localhost)-"
"send(0,5000)-"
"send(5000,5000)-"
"%s"
"disconnected(localhost)-",
ne_iaddr_print(i1, a1, sizeof a1),
recvs);
else
ne_snprintf(buf, buflen,
"lookup(localhost)-"
"connecting(localhost,%s)-"
"connecting(localhost,%s)-"
"connected(localhost)-"
"send(0,5000)-"
"send(5000,5000)-"
"%s"
"disconnected(localhost)-",
ne_iaddr_print(i1, a1, sizeof a1),
ne_iaddr_print(i2, a2, sizeof a2),
recvs);
}

static int notifier(const char *response, const char *recvs)
static int status(void)
{
ne_session *sess;
ne_buffer *buf = ne_buffer_create();
ne_sock_addr *sa = ne_addr_resolve("localhost", 0);
const ne_inet_addr *ia, *ia2;
char *expect[3];
int expects, match;

ONN("could not resolve localhost", ne_addr_result(sa));

ia = ne_addr_first(sa);
ia2 = ne_addr_next(sa);
ONV(ne_addr_next(sa) != NULL,
("dumb test cannot handle localhost with three addresses, sorry"));

expect[0] = ne_malloc(BUFSIZ);
print_addr(expect[0], BUFSIZ, recvs, ia, NULL);

if (ia2) {
expects = 3;
expect[1] = ne_malloc(BUFSIZ);
expect[2] = ne_malloc(BUFSIZ);
print_addr(expect[1], BUFSIZ, recvs, ia, ia2);
print_addr(expect[2], BUFSIZ, recvs, ia2, ia);
}
else {
expects = 1;
}
char expect[1024];

ne_snprintf(expect, sizeof expect,
"lookup(127.0.0.1)-"
"connecting(127.0.0.1,127.0.0.1)-"
"connected(127.0.0.1)-"
"send(0,5000)-"
"send(5000,5000)-"
"recv(0,5)-"
"recv(5,5)-"
"disconnected(127.0.0.1)-");

ne_addr_destroy(sa);

CALL(make_session(&sess, single_serve_string, (char *)response));
CALL(make_session(&sess, single_serve_string, RESP200
"Content-Length: 5\r\n\r\n" "abcde"));

ne_set_notifier(sess, status_cb, buf);

Expand All @@ -2139,43 +2093,54 @@ static int notifier(const char *response, const char *recvs)
ne_session_destroy(sess);
CALL(await_server());

match = 0;
NE_DEBUG(NE_DBG_HTTP, "test: Got %s\n", buf->data);
while (expects-- && !match) {
NE_DEBUG(NE_DBG_HTTP, "test: Checking %s\n", expect[expects]);
if (strcmp(expect[expects], buf->data) == 0)
match = 1;
}

ONV(!match,
ONV(strcmp(expect, buf->data),
("status event sequence mismatch: got [%s] not [%s]",
buf->data, expect[0]));
buf->data, expect));

ne_buffer_destroy(buf);

return OK;
}

static int status_plain(void)
{
return notifier(/* body */
RESP200 "Content-Length: 5\r\n\r\n" "abcde",
/* receive status */
"recv(0,5)-"
"recv(5,5)-");
}

static int status_chunked(void)
{
return notifier(/* body */
RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS,
/* receive status */
"recv(0,-1)-"
"recv(1,-1)-"
"recv(2,-1)-"
"recv(3,-1)-"
"recv(4,-1)-"
"recv(5,-1)-");
ne_session *sess;
ne_buffer *buf = ne_buffer_create();
char expect[1024];

/* This sequence is not exactly guaranteed by the API, but it's
* what the current implementation should do. */
ne_snprintf(expect, sizeof expect,
"lookup(127.0.0.1)-"
"connecting(127.0.0.1,127.0.0.1)-"
"connected(127.0.0.1)-"
"send(0,5000)-"
"send(5000,5000)-"
"recv(0,-1)-"
"recv(1,-1)-"
"recv(2,-1)-"
"recv(3,-1)-"
"recv(4,-1)-"
"recv(5,-1)-"
"disconnected(127.0.0.1)-");

CALL(make_session(&sess, single_serve_string,
RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS));

ne_set_notifier(sess, status_cb, buf);

CALL(any_2xx_request_body(sess, "/status"));

ne_session_destroy(sess);
CALL(await_server());

ONV(strcmp(expect, buf->data),
("status event sequence mismatch: got [%s] not [%s]",
buf->data, expect));

ne_buffer_destroy(buf);

return OK;
}

static const unsigned char raw_127[4] = "\x7f\0\0\01"; /* 127.0.0.1 */
Expand Down Expand Up @@ -2475,7 +2440,7 @@ ne_test tests[] = {
T(hooks),
T(hook_self_destroy),
T(icy_protocol),
T(status_plain),
T(status),
T(status_chunked),
T(local_addr),
T(dereg_progress),
Expand Down
4 changes: 2 additions & 2 deletions test/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int session_server(ne_session **sess, server_fn fn, void *userdata)

CALL(new_spawn_server(1, fn, userdata, &port));

*sess = ne_session_create("http", "localhost", port);
*sess = ne_session_create("http", "127.0.0.1", port);

return OK;
}
Expand All @@ -198,7 +198,7 @@ int proxied_session_server(ne_session **sess, const char *scheme,

NE_DEBUG(NE_DBG_HTTP, "test: Using proxied session to port %u.\n", port);

ne_session_proxy(*sess, "localhost", port);
ne_session_proxy(*sess, "127.0.0.1", port);

return OK;
}
Expand Down

0 comments on commit eff6521

Please sign in to comment.