diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-06 21:01:15 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-06 21:01:15 -0800 |
| commit | 326932d39a9fd457ccf0e9975e378fdac84a0dfa (patch) | |
| tree | 6c2ca476eb7f1a052240d6e93f9f2aa1dfbd9486 /tests | |
| parent | 844f895737bee395ddf3b0659081cb5ac00402cc (diff) | |
| download | nng-326932d39a9fd457ccf0e9975e378fdac84a0dfa.tar.gz nng-326932d39a9fd457ccf0e9975e378fdac84a0dfa.tar.bz2 nng-326932d39a9fd457ccf0e9975e378fdac84a0dfa.zip | |
Fix startup race in the tests.
Pub pipes might not be connected yet. Do the dial from the
pub side synchronously, and we can be sure no data will be lost.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pubsub.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/pubsub.c b/tests/pubsub.c index c2d2362b..a49702d0 100644 --- a/tests/pubsub.c +++ b/tests/pubsub.c @@ -79,8 +79,14 @@ Main({ nng_close(sub); }) - So(nng_listen(pub, addr, NULL, NNG_FLAG_SYNCH) == 0); - So(nng_dial(sub, addr, NULL, NNG_FLAG_SYNCH) == 0); + // Most consumers will usually have the pub listen, + // and the sub dial. However, this creates a problem + // for our tests, since we can wind up trying to push + // data before the pipe is fully registered (the + // accept runs in an asynch thread.) Doing the reverse + // here ensures that we won't lose data. + So(nng_listen(sub, addr, NULL, NNG_FLAG_SYNCH) == 0); + So(nng_dial(pub, addr, NULL, NNG_FLAG_SYNCH) == 0); Convey("Sub can subscribe", { So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "ABC", 3) == 0); @@ -104,7 +110,7 @@ Main({ So(nng_setopt(sub, NNG_OPT_SUBSCRIBE, "/some/", strlen("/some/")) == 0); - rtimeo = 500000; // 500ms + rtimeo = 50000; // 50ms So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0); So(nng_msg_alloc(&msg, 0) == 0); @@ -133,7 +139,7 @@ Main({ Convey("Subs without subsciptions don't receive", { - uint64_t rtimeo = 500000; // 50ms + uint64_t rtimeo = 50000; // 50ms nng_msg *msg; So(nng_setopt(sub, NNG_OPT_RCVTIMEO, &rtimeo, sizeof (rtimeo)) == 0); @@ -145,7 +151,7 @@ Main({ Convey("Subs in raw receive", { - uint64_t rtimeo = 500000; // 50ms + uint64_t rtimeo = 50000; // 500ms int raw = 1; nng_msg *msg; |
