Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gdamore/more tests #1919

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
yml: ./.codecov.yml
codecov_yml_path: ./.codecov.yml

darwin-coverage:
name: darwin
Expand Down
3 changes: 2 additions & 1 deletion src/core/errors_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -15,6 +15,7 @@
static void
test_known_errors(void)
{
NUTS_MATCH(nng_strerror(0), "Hunky dory");
NUTS_MATCH(nng_strerror(NNG_ECLOSED), "Object closed");
NUTS_MATCH(nng_strerror(NNG_ETIMEDOUT), "Timed out");
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@
void
nni_println(const char *msg)
{
// TODO: support redirection of this later.
nni_plat_println(msg);
nni_plat_printf("%s\n", msg);

Check warning on line 72 in src/core/panic.c

View check run for this annotation

Codecov / codecov/patch

src/core/panic.c#L72

Added line #L72 was not covered by tests
}
7 changes: 0 additions & 7 deletions src/platform/posix/posix_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ nni_plat_printf(const char *fmt, ...)
va_end(ap);
}

void
nni_plat_println(const char *message)
{
fputs(message, stderr);
fputc('\n', stderr);
}

const char *
nni_plat_strerror(int errnum)
{
Expand Down
14 changes: 7 additions & 7 deletions src/platform/posix/posix_ipcdial.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void
ipc_dialer_cancel(nni_aio *aio, void *arg, int rv)
{
nni_ipc_dialer *d = arg;
nni_ipc_conn * c;
nni_ipc_conn *c;

nni_mtx_lock(&d->mtx);
if ((!nni_aio_list_active(aio)) ||
Expand All @@ -100,9 +100,9 @@ ipc_dialer_cancel(nni_aio *aio, void *arg, int rv)
static void
ipc_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
{
nni_ipc_conn * c = arg;
nni_ipc_conn *c = arg;
nni_ipc_dialer *d = c->dialer;
nni_aio * aio;
nni_aio *aio;
int rv;

nni_mtx_lock(&d->mtx);
Expand Down Expand Up @@ -153,9 +153,9 @@ ipc_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
void
ipc_dialer_dial(void *arg, nni_aio *aio)
{
ipc_dialer * d = arg;
nni_ipc_conn * c;
nni_posix_pfd * pfd = NULL;
ipc_dialer *d = arg;
nni_ipc_conn *c;
nni_posix_pfd *pfd = NULL;
struct sockaddr_storage ss;
size_t len;
int fd;
Expand Down Expand Up @@ -205,7 +205,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio)
goto error;
}
if (connect(fd, (void *) &ss, len) != 0) {
if (errno != EINPROGRESS) {
if (errno != EINPROGRESS && errno != EAGAIN) {
if (errno == ENOENT) {
// No socket present means nobody listening.
rv = NNG_ECONNREFUSED;
Expand Down
19 changes: 9 additions & 10 deletions src/platform/posix/posix_ipclisten.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

typedef struct {
nng_stream_listener sl;
nni_posix_pfd * pfd;
nni_posix_pfd *pfd;
nng_sockaddr sa;
nni_list acceptq;
bool started;
bool closed;
char * path;
char *path;
mode_t perms;
nni_mtx mtx;
} ipc_listener;
Expand All @@ -45,7 +45,7 @@ static void
ipc_listener_doclose(ipc_listener *l)
{
nni_aio *aio;
char * path;
char *path;

l->closed = true;
while ((aio = nni_list_first(&l->acceptq)) != NULL) {
Expand Down Expand Up @@ -82,7 +82,7 @@ ipc_listener_doaccept(ipc_listener *l)
int fd;
int rv;
nni_posix_pfd *pfd;
nni_ipc_conn * c;
nni_ipc_conn *c;

fd = nni_posix_pfd_fd(l->pfd);

Expand Down Expand Up @@ -302,13 +302,13 @@ ipc_listener_chmod(ipc_listener *l, const char *path)
int
ipc_listener_listen(void *arg)
{
ipc_listener * l = arg;
ipc_listener *l = arg;
socklen_t len;
struct sockaddr_storage ss;
int rv;
int fd;
nni_posix_pfd * pfd;
char * path;
nni_posix_pfd *pfd;
char *path;

if ((len = nni_posix_nn2sockaddr(&ss, &l->sa)) < sizeof(sa_family_t)) {
return (NNG_EADDRINVAL);
Expand Down Expand Up @@ -358,8 +358,7 @@ ipc_listener_listen(void *arg)
}
}

if ((rv != 0) ||
(ipc_listener_chmod(l, path) != 0) ||
if ((rv != 0) || (ipc_listener_chmod(l, path) != 0) ||
(listen(fd, 128) != 0)) {
rv = nni_plat_errno(errno);
}
Expand Down Expand Up @@ -407,7 +406,7 @@ ipc_listener_listen(void *arg)
static void
ipc_listener_free(void *arg)
{
ipc_listener * l = arg;
ipc_listener *l = arg;
nni_posix_pfd *pfd;

nni_mtx_lock(&l->mtx);
Expand Down
6 changes: 0 additions & 6 deletions src/platform/windows/win_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ nni_plat_printf(const char *fmt, ...)
va_end(ap);
}

void
nni_plat_println(const char *message)
{
(void) fprintf(stderr, "%s\n", message);
}

const char *
nni_plat_strerror(int errnum)
{
Expand Down
22 changes: 22 additions & 0 deletions src/sp/transport/ipc/ipc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ test_ipc_connect_blocking_accept(void)
nng_stream_listener_free(l);
}

void
test_ipc_listen_accept_cancel(void)
{
nng_stream_listener *l;
char *addr;
nng_aio *aio;

NUTS_ENABLE_LOG(NNG_LOG_INFO);
NUTS_ADDR(addr, "ipc");
NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL));

// start a listening stream listener but do not call accept
NUTS_PASS(nng_stream_listener_alloc(&l, addr));
NUTS_PASS(nng_stream_listener_listen(l));
nng_stream_listener_accept(l, aio);
nng_msleep(100);
nng_aio_free(aio);
nng_stream_listener_close(l);
nng_stream_listener_free(l);
}

void
test_ipc_listener_clean_stale(void)
{
Expand Down Expand Up @@ -539,6 +560,7 @@ TEST_LIST = {
{ "ipc connect blocking", test_ipc_connect_blocking },
{ "ipc connect blocking accept", test_ipc_connect_blocking_accept },
{ "ipc listen cleanup stale", test_ipc_listener_clean_stale },
{ "ipc listen accept cancel", test_ipc_listen_accept_cancel },
{ "ipc abstract sockets", test_abstract_sockets },
{ "ipc abstract auto bind", test_abstract_auto_bind },
{ "ipc abstract name too long", test_abstract_too_long },
Expand Down
2 changes: 2 additions & 0 deletions src/supplemental/websocket/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,7 @@ nni_ws_listener_alloc(nng_stream_listener **wslp, const nng_url *url)

NNI_LIST_INIT(&l->pend, nni_ws, node);
NNI_LIST_INIT(&l->reply, nni_ws, node);
NNI_LIST_INIT(&l->headers, ws_header, node);

// make a private copy of the url structure.
if ((rv = nng_url_clone(&l->url, url)) != 0) {
Expand Down Expand Up @@ -2651,6 +2652,7 @@ nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
}
NNI_LIST_INIT(&d->headers, ws_header, node);
NNI_LIST_INIT(&d->wspend, nni_ws, node);
NNI_LIST_INIT(&d->headers, ws_header, node);
nni_mtx_init(&d->mtx);
nni_cv_init(&d->cv, &d->mtx);

Expand Down
19 changes: 19 additions & 0 deletions src/supplemental/websocket/websocket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ test_websocket_conn_props(void)
NUTS_PASS(nng_stream_listener_listen(l));
NUTS_PASS(nng_stream_dialer_alloc(&d, uri));

NUTS_PASS(nng_stream_dialer_set_string(
d, NNG_OPT_WS_REQUEST_HEADER "NNG-Req", "True"));

NUTS_PASS(nng_stream_listener_set_string(
l, NNG_OPT_WS_RESPONSE_HEADER "NNG-Rep", "True"));

nng_stream_dialer_dial(d, daio);
nng_stream_listener_accept(l, laio);

Expand Down Expand Up @@ -180,6 +186,19 @@ test_websocket_conn_props(void)
NUTS_FAIL(
nng_stream_get_size(c1, NNG_OPT_TCP_NODELAY, &sz), NNG_EBADTYPE);

NUTS_FAIL(nng_stream_get_string(
c1, NNG_OPT_WS_REQUEST_HEADER "No-Such-Header", &str),
NNG_ENOENT);
NUTS_PASS(nng_stream_get_string(
c1, NNG_OPT_WS_REQUEST_HEADER "NNG-Req", &str));
NUTS_MATCH(str, "True");
nng_strfree(str);

NUTS_PASS(nng_stream_get_string(
c2, NNG_OPT_WS_RESPONSE_HEADER "NNG-Rep", &str));
NUTS_MATCH(str, "True");
nng_strfree(str);

NUTS_PASS(nng_stream_get_string(
c1, NNG_OPT_WS_REQUEST_HEADER "Sec-WebSocket-Version", &str));
NUTS_TRUE(str != NULL);
Expand Down
Loading