You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/09/10 20:19:48 UTC

[5/6] qpid-proton git commit: PROTON-1930: [cpp] Fix race condition in container_test.cpp

PROTON-1930: [cpp] Fix race condition in container_test.cpp

Test was starting container, opening connection and then checking for
["start", "open"] sequence to be set by handlers.

Sometimes the sequence was instead ["open", "start"], which is legal since the
events are generated in different handler contexts.

Fixed by starting container, waiting for "start", opening connection, then
waiting for "open"


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d3c11354
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d3c11354
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d3c11354

Branch: refs/heads/master
Commit: d3c113548146b56cdd8b2a31c2d4dd7ba5dddbfd
Parents: 27edd9a
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Sep 10 12:35:52 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Mon Sep 10 15:50:37 2018 -0400

----------------------------------------------------------------------
 cpp/src/container_test.cpp | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d3c11354/cpp/src/container_test.cpp
----------------------------------------------------------------------
diff --git a/cpp/src/container_test.cpp b/cpp/src/container_test.cpp
index 6f7caa4..0e74aaa 100644
--- a/cpp/src/container_test.cpp
+++ b/cpp/src/container_test.cpp
@@ -366,17 +366,18 @@ void test_container_mt_stop_empty() {
     c.auto_stop( false );
     container_runner runner(c);
     auto t = std::thread(runner);
-    // Must ensure that thread is joined or detached
+    // Must ensure that thread is joined
     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();
-        }
+    } catch (const std::exception &e) {
+        std::cerr << FAIL_MSG(e.what()) << std::endl;
+        // If join hangs, let the test die by timeout.  We cannot
+        // detach and continue: deleting the container while t is
+        // still alive will put the process in an undefined state.
+        t.join();
         throw;
     }
 }
@@ -387,19 +388,20 @@ void test_container_mt_stop() {
     c.auto_stop(false);
     container_runner runner(c);
     auto t = std::thread(runner);
-    // Must ensure that thread is joined or detached
+    // Must ensure that thread is joined
     try {
         test_listen_handler lh;
-        c.listen("//:0", lh);       //  Also opens a connection
         ASSERT_EQUAL("start", th.wait());
+        c.listen("//:0", lh);       //  Also opens a connection
         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();
-        }
+    } catch (const std::exception& e) {
+        std::cerr << FAIL_MSG(e.what()) << std::endl;
+        // If join hangs, let the test die by timeout.  We cannot
+        // detach and continue: deleting the container while t is
+        // still alive will put the process in an undefined state.
+        t.join();
         throw;
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org