From 6d92c73e5cdf93fe70b0646e78a250e01a8d2f65 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 11 Jan 2020 13:15:40 -0800 Subject: XREQ and others race on TTL. The TTL in these cases should have been atomic. To facilitate things we actually introduce an atomic int for convenience. We also introduce a convenience nni_msg_must_append_u32() and nni_msg_header_must_append_u32(), so that we can eliminate some failure tests that cannot ever happen. Combined with a new test for xreq, we have 100% coverage for xreq and more coverage for the other REQ/REP protocols. --- tests/testutil.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tests/testutil.c') diff --git a/tests/testutil.c b/tests/testutil.c index 36999448..356eb333 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -303,20 +303,23 @@ struct marriage_notice { int s2; int cnt1; int cnt2; + nng_pipe p1; + nng_pipe p2; }; static void married(nng_pipe p, nng_pipe_ev ev, void *arg) { struct marriage_notice *notice = arg; - (void) p; (void) ev; nng_mtx_lock(notice->mx); if (nng_socket_id(nng_pipe_socket(p)) == notice->s1) { notice->cnt1++; + notice->p1 = p; } else if (nng_socket_id(nng_pipe_socket(p)) == notice->s2) { notice->cnt2++; + notice->p2 = p; } nng_cv_wake(notice->cv); nng_mtx_unlock(notice->mx); @@ -324,6 +327,12 @@ married(nng_pipe p, nng_pipe_ev ev, void *arg) int testutil_marry(nng_socket s1, nng_socket s2) +{ + return (testutil_marry_ex(s1, s2, NULL, NULL)); +} + +int +testutil_marry_ex(nng_socket s1, nng_socket s2, nng_pipe *p1, nng_pipe *p2) { struct marriage_notice note; nng_time timeout; @@ -357,6 +366,12 @@ testutil_marry(nng_socket s1, nng_socket s2) } } nng_mtx_unlock(note.mx); + if (p1 != NULL) { + *p1 = note.p1; + } + if (p2 != NULL) { + *p2 = note.p2; + } done: nng_pipe_notify(s1, NNG_PIPE_EV_ADD_POST, NULL, NULL); -- cgit v1.2.3-70-g09d2