aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-07-02 12:44:42 -0700
committerGarrett D'Amore <garrett@damore.org>2018-07-02 12:44:42 -0700
commita772bcc6ebe198f939889abbda18eded2a326941 (patch)
treeab48eefaefdb242682fbe84c89a0557307242946 /tests
parent63418ae95eb9d61d2cffa56f7e8fbdb48aaaf703 (diff)
downloadnng-a772bcc6ebe198f939889abbda18eded2a326941.tar.gz
nng-a772bcc6ebe198f939889abbda18eded2a326941.tar.bz2
nng-a772bcc6ebe198f939889abbda18eded2a326941.zip
fixes #564 Race regression caused by#522
fixes #565 Option getting should validate sizes more aggressively fixes #563 Reconnect timeouts should be settable on dialers fixes #562 pipe test is fragile
Diffstat (limited to 'tests')
-rw-r--r--tests/pipe.c100
-rw-r--r--tests/sock.c2
2 files changed, 64 insertions, 38 deletions
diff --git a/tests/pipe.c b/tests/pipe.c
index 79006fc8..dfebbd56 100644
--- a/tests/pipe.c
+++ b/tests/pipe.c
@@ -15,6 +15,7 @@
#include "supplemental/util/platform.h"
#include "stubs.h"
+#include <stdbool.h>
#include <string.h>
#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s))
@@ -33,16 +34,27 @@ struct testcase {
int err;
int rej;
nng_mtx * lk;
+ nng_cv * cv;
};
-static int
-getval(struct testcase *t, int *vp)
+static bool
+expect(struct testcase *t, int *vp, int v)
{
- int rv;
+ bool ok;
+ nng_time when = nng_clock() + 5000; // five seconds
+
nng_mtx_lock(t->lk);
- rv = *vp;
+ while (*vp != v) {
+ if (nng_cv_until(t->cv, when) == NNG_ETIMEDOUT) {
+ break;
+ }
+ }
+ ok = (*vp == v) ? true : false;
+ if (!ok) {
+ printf("Expected %d but got %d\n", v, *vp);
+ }
nng_mtx_unlock(t->lk);
- return (rv);
+ return (ok);
}
void
@@ -55,6 +67,7 @@ notify(nng_pipe p, int act, void *arg)
(nng_listener_id(nng_pipe_listener(p)) != nng_listener_id(t->l)) ||
(nng_dialer_id(nng_pipe_dialer(p)) != nng_dialer_id(t->d))) {
t->err++;
+ nng_cv_wake(t->cv);
nng_mtx_unlock(t->lk);
return;
}
@@ -73,9 +86,12 @@ notify(nng_pipe p, int act, void *arg)
break;
default:
t->err++;
+ nng_cv_wake(t->cv);
+ nng_mtx_unlock(t->lk);
return;
}
t->p = p;
+ nng_cv_wake(t->cv);
nng_mtx_unlock(t->lk);
}
@@ -107,17 +123,26 @@ TestMain("Pipe notify works", {
memset(&pull, 0, sizeof(pull));
memset(&push, 0, sizeof(push));
So(nng_mtx_alloc(&push.lk) == 0);
+ So(nng_cv_alloc(&push.cv, push.lk) == 0);
So(nng_mtx_alloc(&pull.lk) == 0);
+ So(nng_cv_alloc(&pull.cv, pull.lk) == 0);
So(nng_push_open(&push.s) == 0);
So(nng_pull_open(&pull.s) == 0);
Reset({
nng_close(push.s);
nng_close(pull.s);
+ nng_cv_free(push.cv);
+ nng_cv_free(pull.cv);
nng_mtx_free(push.lk);
nng_mtx_free(pull.lk);
});
+ So(nng_setopt_ms(push.s, NNG_OPT_RECONNMINT, 10) == 0);
+ So(nng_setopt_ms(push.s, NNG_OPT_RECONNMAXT, 10) == 0);
+ So(nng_setopt_ms(pull.s, NNG_OPT_RECONNMINT, 10) == 0);
+ So(nng_setopt_ms(pull.s, NNG_OPT_RECONNMAXT, 10) == 0);
+
So(nng_pipe_notify(
push.s, NNG_PIPE_EV_ADD_PRE, notify, &push) == 0);
So(nng_pipe_notify(
@@ -131,25 +156,27 @@ TestMain("Pipe notify works", {
So(nng_pipe_notify(
pull.s, NNG_PIPE_EV_REM_POST, notify, &pull) == 0);
- So(nng_setopt_ms(push.s, NNG_OPT_RECONNMINT, 10) == 0);
- So(nng_setopt_ms(push.s, NNG_OPT_RECONNMAXT, 10) == 0);
-
Convey("Dialing works", {
So(nng_listener_create(&pull.l, pull.s, addr) == 0);
So(nng_dialer_create(&push.d, push.s, addr) == 0);
So(nng_listener_id(pull.l) > 0);
So(nng_dialer_id(push.d) > 0);
+ So(nng_dialer_setopt_ms(
+ push.d, NNG_OPT_RECONNMINT, 10) == 0);
+ So(nng_dialer_setopt_ms(
+ push.d, NNG_OPT_RECONNMAXT, 10) == 0);
So(nng_listener_start(pull.l, 0) == 0);
So(nng_dialer_start(push.d, 0) == 0);
- nng_msleep(100);
- So(getval(&pull, &pull.add_pre) == 1);
- So(getval(&pull, &pull.add_post) == 1);
- So(getval(&pull, &pull.rem) == 0);
- So(getval(&pull, &pull.err) == 0);
- So(getval(&push, &push.add_pre) == 1);
- So(getval(&push, &push.add_post) == 1);
- So(getval(&push, &push.rem) == 0);
- So(getval(&push, &push.err) == 0);
+ So(expect(&pull, &pull.add_pre, 1));
+ So(expect(&pull, &pull.add_post, 1));
+ So(expect(&pull, &pull.add_pre, 1));
+ So(expect(&pull, &pull.add_post, 1));
+ So(expect(&pull, &pull.rem, 0));
+ So(expect(&pull, &pull.err, 0));
+ So(expect(&push, &push.add_pre, 1));
+ So(expect(&push, &push.add_post, 1));
+ So(expect(&push, &push.rem, 0));
+ So(expect(&push, &push.err, 0));
Convey("We can send a frame", {
nng_msg *msg;
@@ -166,20 +193,19 @@ TestMain("Pipe notify works", {
});
Convey("Reconnection works", {
- So(getval(&pull, &pull.add_pre) == 1);
- So(getval(&pull, &pull.add_post) == 1);
+ So(expect(&pull, &pull.add_pre, 1));
+ So(expect(&pull, &pull.add_post, 1));
nng_pipe_close(pull.p);
- nng_msleep(200);
- So(getval(&pull, &pull.err) == 0);
- So(getval(&pull, &pull.rem) == 1);
- So(getval(&pull, &pull.add_pre) == 2);
- So(getval(&pull, &pull.add_post) == 2);
+ So(expect(&pull, &pull.rem, 1));
+ So(expect(&pull, &pull.err, 0));
+ So(expect(&pull, &pull.add_pre, 2));
+ So(expect(&pull, &pull.add_post, 2));
- So(getval(&push, &push.err) == 0);
- So(getval(&push, &push.rem) == 1);
- So(getval(&push, &push.add_pre) == 2);
- So(getval(&push, &push.add_post) == 2);
+ So(expect(&push, &push.rem, 1));
+ So(expect(&push, &push.err, 0));
+ So(expect(&push, &push.add_pre, 2));
+ So(expect(&push, &push.add_post, 2));
Convey("They still exchange frames", {
nng_msg *msg;
@@ -209,16 +235,16 @@ TestMain("Pipe notify works", {
So(nng_listener_id(pull.l) > 0);
So(nng_dialer_id(push.d) > 0);
So(nng_listener_start(pull.l, 0) == 0);
- So(nng_dialer_start(push.d, 0) == 0);
nng_msleep(100);
- So(getval(&pull, &pull.add_pre) == 2);
- So(getval(&pull, &pull.add_post) == 1);
- So(getval(&pull, &pull.rem) == 1);
- So(getval(&pull, &pull.err) == 0);
- So(getval(&push, &push.add_pre) == 2);
- So(getval(&push, &push.add_post) == 2);
- So(getval(&push, &push.rem) == 1);
- So(getval(&push, &push.err) == 0);
+ So(nng_dialer_start(push.d, 0) == 0);
+ So(expect(&pull, &pull.add_pre, 2));
+ So(expect(&pull, &pull.add_post, 1));
+ So(expect(&pull, &pull.rem, 1));
+ So(expect(&pull, &pull.err, 0));
+ So(expect(&push, &push.add_pre, 2));
+ So(expect(&push, &push.add_post, 2));
+ So(expect(&push, &push.rem, 1) == 1);
+ So(expect(&push, &push.err, 0));
});
});
})
diff --git a/tests/sock.c b/tests/sock.c
index 3792090b..002ae944 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -387,7 +387,7 @@ TestMain("Socket Operations", {
// Not appropriate for dialer.
So(nng_dialer_setopt_bool(
ep, NNG_OPT_RAW, true) == NNG_ENOTSUP);
- So(nng_dialer_setopt_ms(ep, NNG_OPT_RECONNMINT,
+ So(nng_dialer_setopt_ms(ep, NNG_OPT_SENDTIMEO,
1) == NNG_ENOTSUP);
So(nng_dialer_setopt_string(ep,
NNG_OPT_SOCKNAME,