Repository: qpid-proton Updated Branches: refs/heads/master ec97465f8 -> b44e3fffb
NO_JIRA: [c] Fix minor proactor test bugs Some tests were listening on default AMQP port instead of port 0. Improved idle-timeout logic for test proactor. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b44e3fff Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b44e3fff Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b44e3fff Branch: refs/heads/master Commit: b44e3fffbe097d528c4156632337be0c603427f5 Parents: ec97465 Author: Alan Conway <acon...@redhat.com> Authored: Tue Dec 4 16:06:45 2018 -0500 Committer: Alan Conway <acon...@redhat.com> Committed: Tue Dec 4 16:23:19 2018 -0500 ---------------------------------------------------------------------- c/tests/pn_test_proactor.cpp | 28 +++++++++++++++++----------- c/tests/pn_test_proactor.hpp | 12 ++++++++---- c/tests/proactor_test.cpp | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b44e3fff/c/tests/pn_test_proactor.cpp ---------------------------------------------------------------------- diff --git a/c/tests/pn_test_proactor.cpp b/c/tests/pn_test_proactor.cpp index 0c06f72..40ceca7 100644 --- a/c/tests/pn_test_proactor.cpp +++ b/c/tests/pn_test_proactor.cpp @@ -92,30 +92,36 @@ pn_event_type_t proactor::run(pn_event_type_t stop) { } } -pn_event_type_t proactor::flush(pn_event_type_t stop) { +std::pair<int, pn_event_type_t> proactor::flush(pn_event_type_t stop) { auto_batch b(*this, pn_proactor_get(*this)); + int n = 0; if (b.get()) { pn_event_t *e; while ((e = b.next())) { pn_event_type_t et = pn_event_type(e); - if (dispatch(e) || et == stop) return et; + if (dispatch(e) || et == stop) return std::make_pair(n, et); } } - return PN_EVENT_NONE; + return std::make_pair(n, PN_EVENT_NONE); } pn_event_type_t proactor::corun(proactor &other, pn_event_type_t stop) { - // We can't wait() on either proactor as it might be idle until + // We can't wait() on either proactor as it might be idle. + // We can't give up immediately if both proactors are idle // something happens on the other, so spin between the two for a limited // number of attempts that should be large enough if the test is going to - // past. + // pass. int spin_limit = 1000; - while (spin_limit > 0) { - pn_event_type_t et = flush(stop); - if (et) return et; - other.flush(); - --spin_limit; - } + do { + std::pair<int, pn_event_type_t> n_et = flush(stop); + if (n_et.second) return n_et.second; + if (n_et.first + other.flush().first == 0) { + // Both idle, sleep and retry in case network traffic is in flight. + millisleep(1); + --spin_limit; + } + } while (spin_limit); + return PN_EVENT_NONE; } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b44e3fff/c/tests/pn_test_proactor.hpp ---------------------------------------------------------------------- diff --git a/c/tests/pn_test_proactor.hpp b/c/tests/pn_test_proactor.hpp index 3703910..239992a 100644 --- a/c/tests/pn_test_proactor.hpp +++ b/c/tests/pn_test_proactor.hpp @@ -69,15 +69,19 @@ struct proactor : auto_free<pn_proactor_t, pn_proactor_free> { // * The `stop` event type is handled. // * All available events are flushed. // - // Return PN_EVENT_NONE if all events were flushed, the event-type of the last - // event handled otherwise. - pn_event_type_t flush(pn_event_type_t stop = PN_EVENT_NONE); + // Returns the number of events processed and + // - PN_EVENT_NONE if all events were handled without stopping + // - The type of the last event handled otherwise + // + std::pair<int, pn_event_type_t> flush(pn_event_type_t stop = PN_EVENT_NONE); // Alternate flushing this proactor and `other` until // * A handler on this proactor returns true. // * The `stop` event type is handled by this proactor. + // * Both proactors become idle. + // // Return the event-type of the last event handled or PN_EVENT_NONE - // if something went wrong. + // if the proactors are idle. pn_event_type_t corun(proactor &other, pn_event_type_t stop = PN_EVENT_NONE); // Wait for and handle a single event, return it's type. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b44e3fff/c/tests/proactor_test.cpp ---------------------------------------------------------------------- diff --git a/c/tests/proactor_test.cpp b/c/tests/proactor_test.cpp index 971c231..3e4365a 100644 --- a/c/tests/proactor_test.cpp +++ b/c/tests/proactor_test.cpp @@ -166,7 +166,7 @@ TEST_CASE("proactor_connection_wake") { common_handler h; proactor p(&h); close_on_wake_handler wh; - pn_listener_t *l = p.listen(":0"); + pn_listener_t *l = p.listen(); REQUIRE_RUN(p, PN_LISTENER_OPEN); pn_connection_t *c = p.connect(l, &wh); pn_incref(c); /* Keep a reference for wake() after free */ @@ -330,7 +330,7 @@ TEST_CASE("proactor_errors") { REQUIRE_RUN(p, PN_PROACTOR_INACTIVE); /* Listen on a port already in use */ - l = p.listen(":0"); + l = p.listen(); REQUIRE_RUN(p, PN_LISTENER_OPEN); std::string laddr = ":" + listening_port(l); p.listen(laddr); @@ -388,10 +388,10 @@ TEST_CASE("proactor_ipv4_ipv6") { proactor p(&h); /* Listen on all interfaces for IPv4 only. */ - pn_listener_t *l4 = p.listen("0.0.0.0"); + pn_listener_t *l4 = p.listen("0.0.0.0:0"); REQUIRE_RUN(p, PN_LISTENER_OPEN); /* Empty address listens on both IPv4 and IPv6 on all interfaces */ - pn_listener_t *l = p.listen(":0"); + pn_listener_t *l = p.listen(); REQUIRE_RUN(p, PN_LISTENER_OPEN); #define EXPECT_CONNECT(LISTENER, HOST) \ @@ -435,7 +435,7 @@ TEST_CASE("proactor_release_free") { common_handler h; proactor p(&h); - pn_listener_t *l = p.listen(":0"); + pn_listener_t *l = p.listen(); REQUIRE_RUN(p, PN_LISTENER_OPEN); /* leave one connection to the proactor */ pn_connection_t *c = p.connect(l); @@ -592,7 +592,7 @@ TEST_CASE("proactor_netaddr") { common_handler h; proactor p(&h); /* Use IPv4 to get consistent results all platforms */ - pn_listener_t *l = p.listen("127.0.0.1"); + pn_listener_t *l = p.listen("127.0.0.1:0"); REQUIRE_RUN(p, PN_LISTENER_OPEN); pn_connection_t *c = p.connect(l); REQUIRE_RUN(p, PN_CONNECTION_REMOTE_OPEN); @@ -674,9 +674,9 @@ TEST_CASE("proactor_disconnect") { proactor client(&ch), server(&sh); // Start two listeners on the server - pn_listener_t *l = server.listen(":0"); + pn_listener_t *l = server.listen(); REQUIRE_RUN(server, PN_LISTENER_OPEN); - pn_listener_t *l2 = server.listen(":0"); + pn_listener_t *l2 = server.listen(); REQUIRE_RUN(server, PN_LISTENER_OPEN); // Two connections from client @@ -714,7 +714,7 @@ TEST_CASE("proactor_disconnect") { REQUIRE_RUN(server, PN_PROACTOR_INACTIVE); /* Make sure the proactors are still functional */ - pn_listener_t *l3 = server.listen(":0"); + pn_listener_t *l3 = server.listen(); REQUIRE_RUN(server, PN_LISTENER_OPEN); client.connect(l3); CHECK_CORUN(client, server, PN_CONNECTION_REMOTE_OPEN); @@ -800,7 +800,7 @@ TEST_CASE("proactor_message_stream") { message_stream_handler h; proactor p(&h); - pn_listener_t *l = p.listen(":0"); + pn_listener_t *l = p.listen(); REQUIRE_RUN(p, PN_LISTENER_OPEN); /* Encode a large (not very) message to send in chunks */ --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org