Skip to content

Commit

Permalink
Fix status, status_chunked tests.
Browse files Browse the repository at this point in the history
* test/utils.c (session_server): Store the hostname.
  (get_session_host): New function.

* test/request.c (status, status_chunked): Use get_session_host() to
  accurately create the expected status notifier output.
  • Loading branch information
notroj committed Jan 28, 2024
1 parent a65f9a2 commit 3203d95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
26 changes: 14 additions & 12 deletions test/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,22 +1976,23 @@ static int status(void)
{
ne_session *sess;
ne_buffer *buf = ne_buffer_create();
const char *lh_addr = get_lh_addr();
const char *host, *addr = get_lh_addr();
char expect[1024];

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

host = get_session_host();

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

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

ne_set_notifier(sess, status_cb, buf);

Expand All @@ -2012,13 +2013,17 @@ static int status_chunked(void)
{
ne_session *sess;
ne_buffer *buf = ne_buffer_create();
const char *lh_addr = get_lh_addr();
const char *host, *addr = get_lh_addr();
char expect[1024];

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

host = get_session_host();

/* This sequence is not exactly guaranteed by the API, but it's
* what the current implementation should do. */
ne_snprintf(expect, sizeof expect,
"lookup(%s)-"
"connecting(%s,%s)-"
"connected(%s)-"
"send(0,5000)-"
Expand All @@ -2030,10 +2035,7 @@ static int status_chunked(void)
"recv(4,-1)-"
"recv(5,-1)-"
"disconnected(%s)-",
lh_addr, lh_addr, lh_addr, lh_addr, lh_addr);

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

ne_set_notifier(sess, status_cb, buf);

Expand Down
21 changes: 10 additions & 11 deletions test/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "tests.h"
#include "utils.h"

static char session_host[128];

int serve_response(ne_socket *s, const char *response)
{
CALL(discard_request(s));
Expand Down Expand Up @@ -204,24 +206,21 @@ int multi_session_server(ne_session **sess,
return OK;
}

int session_server(ne_session **sess, server_fn fn, void *userdata)
const char *get_session_host(void)
{
char *host6 = NULL;
const char *host;
int ret;
return session_host;
}

int session_server(ne_session **sess, server_fn fn, void *userdata)
{
if (get_lh_family() == AF_INET6) {
host = host6 = ne_concat("[", get_lh_addr(), "]", NULL);
ne_snprintf(session_host, sizeof session_host, "[%s]", get_lh_addr());
}
else {
host = get_lh_addr();
ne_strnzcpy(session_host, get_lh_addr(), sizeof session_host);
}

ret = multi_session_server(sess, "http", host, 1, fn, userdata);

if (host6) ne_free(host6);

return ret;
return multi_session_server(sess, "http", session_host, 1, fn, userdata);
}

int proxied_session_server(ne_session **sess, const char *scheme,
Expand Down
3 changes: 3 additions & 0 deletions test/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ int any_2xx_request_method(ne_session *sess, const char *method,
* CALL(make_session(...)); */
int make_session(ne_session **sess, server_fn fn, void *userdata);

/* Returns hostname used for make_session(). */
const char *get_session_host(void);

/* Server which sleeps for 10 seconds then closes the socket. */
int sleepy_server(ne_socket *sock, void *userdata);

Expand Down

0 comments on commit 3203d95

Please sign in to comment.