Repository: qpid-proton Updated Branches: refs/heads/master b2525c5fa -> 4e87a519c
PROTON-1897: Make sure that we don't exit tests with unjoined threads - The tests signal assertion failures with exceptions if there are unjoined threads the assertion failure exceptions get overridden by terminate due to threads still hanging about. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4e87a519 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4e87a519 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4e87a519 Branch: refs/heads/master Commit: 4e87a519c5b86015b236cbdaacefc84ff4298c4b Parents: b2525c5 Author: Andrew Stitcher <[email protected]> Authored: Wed Jul 18 00:57:19 2018 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Wed Jul 18 00:57:19 2018 -0400 ---------------------------------------------------------------------- cpp/src/container_test.cpp | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4e87a519/cpp/src/container_test.cpp ---------------------------------------------------------------------- diff --git a/cpp/src/container_test.cpp b/cpp/src/container_test.cpp index eb79f30..5bb9260 100644 --- a/cpp/src/container_test.cpp +++ b/cpp/src/container_test.cpp @@ -360,33 +360,46 @@ class container_runner { void operator()() {c_.run();} }; -int test_container_mt_stop_empty() { +void test_container_mt_stop_empty() { test_mt_handler th; proton::container c(th); c.auto_stop( false ); container_runner runner(c); auto t = std::thread(runner); - ASSERT_EQUAL("start", th.wait()); - c.stop(); - t.join(); - ASSERT_EQUAL("", th.error().name()); - return 0; + // Must ensure that thread is joined or detached + try { + ASSERT_EQUAL("start", th.wait()); + c.stop(); + t.join(); + ASSERT_EQUAL("", th.error().name()); + } catch (...) { + // We don't join as we don't know if we'll be stuck waiting + if (t.joinable()) { + t.detach(); + } + } } -int test_container_mt_stop() { +void test_container_mt_stop() { test_mt_handler th; proton::container c(th); c.auto_stop(false); container_runner runner(c); auto t = std::thread(runner); - test_listen_handler lh; - c.listen("//:0", lh); // Also opens a connection - ASSERT_EQUAL("start", th.wait()); - ASSERT_EQUAL("open", th.wait()); - c.stop(); - t.join(); - // It is possible to get sporadic connection errors from this test depending on timing of stop() - return 0; + // Must ensure that thread is joined or detached + try { + test_listen_handler lh; + c.listen("//:0", lh); // Also opens a connection + ASSERT_EQUAL("start", th.wait()); + ASSERT_EQUAL("open", th.wait()); + c.stop(); + t.join(); + } catch (...) { + // We don't join as we don't know if we'll be stuck waiting + if (t.joinable()) { + t.detach(); + } + } } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
