aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-12 12:24:54 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-14 13:43:02 -0700
commit343417234aa3fd86e8ae0b56ae500a1ed3411cfc (patch)
tree728992cfe8c2987d5939026a1f734dcc58b3df18 /tests
parent4fb81f024e5f32a186cd5538574f8e5796980e36 (diff)
downloadnng-343417234aa3fd86e8ae0b56ae500a1ed3411cfc.tar.gz
nng-343417234aa3fd86e8ae0b56ae500a1ed3411cfc.tar.bz2
nng-343417234aa3fd86e8ae0b56ae500a1ed3411cfc.zip
fixes #62 Endpoint close should be synchronous #62
fixes #66 Make pipe and endpoint structures private This changes a number of things, refactoring endpoints and supporting code to keep their internals private, and making endpoint close synchronous. This will allow us to add a consumer facing API for nng_ep_close(), as well as property APIs, etc. While here a bunch of convoluted and dead code was cleaned up.
Diffstat (limited to 'tests')
-rw-r--r--tests/event.c141
-rw-r--r--tests/pair1.c3
-rw-r--r--tests/trantest.h54
3 files changed, 99 insertions, 99 deletions
diff --git a/tests/event.c b/tests/event.c
index b2d15780..d6fadc5a 100644
--- a/tests/event.c
+++ b/tests/event.c
@@ -22,8 +22,10 @@ struct evcnt {
int writeable;
int pipeadd;
int piperem;
- int epadd;
- int eprem;
+ int dialeradd;
+ int dialerrem;
+ int listeneradd;
+ int listenerrem;
int err;
};
@@ -42,6 +44,8 @@ bump(nng_event *ev, void *arg)
cnt->readable = 1;
break;
+#if 0 // These are not tested yet
+
case NNG_EV_PIPE_ADD:
cnt->pipeadd = 1;
break;
@@ -50,94 +54,97 @@ bump(nng_event *ev, void *arg)
cnt->piperem = 1;
break;
- case NNG_EV_ENDPT_ADD:
- cnt->epadd = 1;
+ case NNG_EV_DIALER_ADD:
+ cnt->dialeradd = 1;
+ break;
+
+ case NNG_EV_DIALER_REM:
+ cnt->dialerrem = 1;
+ break;
+
+ case NNG_EV_LISTENER_ADD:
+ cnt->listeneradd = 1;
break;
- case NNG_EV_ENDPT_REM:
- cnt->eprem = 1;
+ case NNG_EV_LISTENER_REM:
+ cnt->listenerrem = 1;
break;
+#endif
default:
- assert(0);
break;
}
}
-Main({
+TestMain("Event Handling", {
const char *addr = "inproc://test";
+ Convey("Given a connected pair of pair sockets", {
+ nng_socket sock1;
+ nng_socket sock2;
+ struct evcnt evcnt1;
+ struct evcnt evcnt2;
+ nng_notify * notify1;
+ nng_notify * notify2;
+
+ So(nng_pair0_open(&sock1) == 0);
+ So(nng_pair0_open(&sock2) == 0);
+
+ memset(&evcnt1, 0, sizeof(evcnt1));
+ memset(&evcnt2, 0, sizeof(evcnt2));
+ evcnt1.sock = sock1;
+ evcnt2.sock = sock2;
+
+ Reset({
+ nng_close(sock1);
+ nng_close(sock2);
+ });
- Test("Event Handling", {
- Convey("Given a connected pair of pair sockets", {
- nng_socket sock1;
- nng_socket sock2;
- struct evcnt evcnt1;
- struct evcnt evcnt2;
- nng_notify * notify1;
- nng_notify * notify2;
-
- So(nng_pair0_open(&sock1) == 0);
- So(nng_pair0_open(&sock2) == 0);
-
- memset(&evcnt1, 0, sizeof(evcnt1));
- memset(&evcnt2, 0, sizeof(evcnt2));
- evcnt1.sock = sock1;
- evcnt2.sock = sock2;
-
- Reset({
- nng_close(sock1);
- nng_close(sock2);
- });
-
- So(nng_listen(sock1, addr, NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(sock2, addr, NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_listen(sock1, addr, NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_dial(sock2, addr, NULL, NNG_FLAG_SYNCH) == 0);
- // Let everything connect.
- nng_usleep(100000);
+ // Let everything connect.
+ nng_usleep(100000);
- Convey("We can register callbacks", {
- So((notify1 = nng_setnotify(sock1,
- NNG_EV_CAN_SND, bump, &evcnt1)) !=
- NULL);
- So((notify2 = nng_setnotify(sock2,
- NNG_EV_CAN_RCV, bump, &evcnt2)) !=
- NULL);
+ Convey("We can register callbacks", {
+ So((notify1 = nng_setnotify(sock1, NNG_EV_CAN_SND,
+ bump, &evcnt1)) != NULL);
+ So((notify2 = nng_setnotify(sock2, NNG_EV_CAN_RCV,
+ bump, &evcnt2)) != NULL);
- Convey("They are called", {
- nng_msg *msg;
+ Convey("They are called", {
+ nng_msg *msg;
- So(nng_msg_alloc(&msg, 0) == 0);
- APPENDSTR(msg, "abc");
+ So(nng_msg_alloc(&msg, 0) == 0);
+ APPENDSTR(msg, "abc");
- So(nng_sendmsg(sock1, msg, 0) == 0);
+ So(nng_sendmsg(sock1, msg, 0) == 0);
- // XXX: The current implementation
- // is level rather than edge triggered.
- // Think through the ramifications of
- // this. Probably the msgq needs to
- // toggle on reads.
+ // XXX: The current implementation
+ // is level rather than edge triggered.
+ // Think through the ramifications of
+ // this. Probably the msgq needs to
+ // toggle on reads.
- // nng_usleep(20000);
+ // nng_usleep(20000);
- // So(nng_recvmsg(sock2, &msg, 0) ==
- // 0);
+ // So(nng_recvmsg(sock2, &msg, 0) ==
+ // 0);
- // CHECKSTR(msg, "abc");
- // nng_msg_free(msg);
+ // CHECKSTR(msg, "abc");
+ // nng_msg_free(msg);
- // The notify runs async...
- nng_usleep(100000);
+ // The notify runs async...
+ nng_usleep(100000);
- So(evcnt1.writeable == 1);
- So(evcnt2.readable == 1);
- });
+ So(evcnt1.writeable == 1);
+ So(evcnt2.readable == 1);
+ });
- Convey("We can unregister them", {
- nng_unsetnotify(sock1, notify1);
- So(1);
- nng_unsetnotify(sock2, notify2);
- So(1);
- });
+ Convey("We can unregister them", {
+ nng_unsetnotify(sock1, notify1);
+ So(1);
+ nng_unsetnotify(sock2, notify2);
+ So(1);
});
});
});
diff --git a/tests/pair1.c b/tests/pair1.c
index 5a8311e2..c5916e82 100644
--- a/tests/pair1.c
+++ b/tests/pair1.c
@@ -73,7 +73,6 @@ TestMain("PAIRv1 protocol", {
});
Convey("Monogamous mode ignores new conns", {
- int rv;
nng_msg *msg;
So(nng_listen(s1, addr, NULL, NNG_FLAG_SYNCH) == 0);
@@ -394,8 +393,6 @@ TestMain("PAIRv1 protocol", {
Convey("Polyamorous default works", {
nng_msg *msg;
- nng_pipe p1;
- size_t sz;
So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == 0);
diff --git a/tests/trantest.h b/tests/trantest.h
index 74e533bf..639d0632 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -82,14 +82,14 @@ void
trantest_conn_refused(trantest *tt)
{
Convey("Connection refused works", {
- nng_endpoint ep = 0;
+ nng_dialer d = 0;
- So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
+ So(nng_dial(tt->reqsock, tt->addr, &d, NNG_FLAG_SYNCH) ==
NNG_ECONNREFUSED);
- So(ep == 0);
- So(nng_dial(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
+ So(d == 0);
+ So(nng_dial(tt->repsock, tt->addr, &d, NNG_FLAG_SYNCH) ==
NNG_ECONNREFUSED);
- So(ep == 0);
+ So(d == 0);
})
}
@@ -97,14 +97,13 @@ void
trantest_duplicate_listen(trantest *tt)
{
Convey("Duplicate listen rejected", {
- nng_endpoint ep;
- So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
- 0);
- So(ep != 0);
- ep = 0;
- So(nng_listen(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
+ nng_listener l;
+ So(nng_listen(tt->repsock, tt->addr, &l, NNG_FLAG_SYNCH) == 0);
+ So(l != 0);
+ l = 0;
+ So(nng_listen(tt->reqsock, tt->addr, &l, NNG_FLAG_SYNCH) ==
NNG_EADDRINUSE);
- So(ep == 0);
+ So(l == 0);
})
}
@@ -112,15 +111,14 @@ void
trantest_listen_accept(trantest *tt)
{
Convey("Listen and accept", {
- nng_endpoint ep;
- ep = 0;
- So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
- 0);
- So(ep != 0);
-
- ep = 0;
- So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0);
- So(ep != 0);
+ nng_listener l;
+ nng_dialer d;
+ So(nng_listen(tt->repsock, tt->addr, &l, NNG_FLAG_SYNCH) == 0);
+ So(l != 0);
+
+ d = 0;
+ So(nng_dial(tt->reqsock, tt->addr, &d, NNG_FLAG_SYNCH) == 0);
+ So(d != 0);
})
}
@@ -128,18 +126,16 @@ void
trantest_send_recv(trantest *tt)
{
Convey("Send and recv", {
- nng_endpoint ep = 0;
+ nng_listener l;
+ nng_dialer d;
nng_msg * send;
nng_msg * recv;
size_t len;
- ep = 0;
- So(nng_listen(tt->repsock, tt->addr, &ep, NNG_FLAG_SYNCH) ==
- 0);
- So(ep != 0);
- ep = 0;
- So(nng_dial(tt->reqsock, tt->addr, &ep, NNG_FLAG_SYNCH) == 0);
- So(ep != 0);
+ So(nng_listen(tt->repsock, tt->addr, &l, NNG_FLAG_SYNCH) == 0);
+ So(l != 0);
+ So(nng_dial(tt->reqsock, tt->addr, &d, NNG_FLAG_SYNCH) == 0);
+ So(d != 0);
send = NULL;
So(nng_msg_alloc(&send, 0) == 0);