From 326932d39a9fd457ccf0e9975e378fdac84a0dfa Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 6 Jan 2017 21:01:15 -0800 Subject: 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. --- tests/pubsub.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/pubsub.c') 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; -- cgit v1.2.3-70-g09d2