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 0d9ce52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
24 changes: 14 additions & 10 deletions test/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,9 +1976,14 @@ 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)-"
Expand All @@ -1988,10 +1993,7 @@ static int status(void)
"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, host, addr, host, host);

ne_set_notifier(sess, status_cb, buf);

Expand All @@ -2012,9 +2014,14 @@ 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,
Expand All @@ -2030,10 +2037,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, host, addr, host, host);

ne_set_notifier(sess, status_cb, buf);

Expand Down
17 changes: 10 additions & 7 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,22 +206,23 @@ int multi_session_server(ne_session **sess,
return OK;
}

const char *get_session_host(void)
{
return session_host;
}

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

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);
ret = multi_session_server(sess, "http", session_host, 1, fn, userdata);

return ret;
}
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 0d9ce52

Please sign in to comment.