Repository: qpid-proton
Updated Branches:
  refs/heads/master bbc83aaf0 -> 2b51dcf56


PROTON-1734: [C++ binding] Extra tests to check that you can stop container
- This tests that pn_proactor_disconnect() can always be used even when
  the container/proactor is inactive.


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

Branch: refs/heads/master
Commit: 0df65cc3ced56e46044981b09e7bf25a84de69ee
Parents: 5d47e61
Author: Andrew Stitcher <astitc...@apache.org>
Authored: Thu Feb 22 02:02:16 2018 -0500
Committer: Andrew Stitcher <astitc...@apache.org>
Committed: Thu Feb 22 10:40:15 2018 -0500

----------------------------------------------------------------------
 proton-c/bindings/cpp/CMakeLists.txt         |  2 +-
 proton-c/bindings/cpp/src/container_test.cpp | 95 ++++++++++++++++++++++-
 2 files changed, 94 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0df65cc3/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt 
b/proton-c/bindings/cpp/CMakeLists.txt
index b32b3f8..6555c4c 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -220,7 +220,7 @@ install (FILES
 
 macro(add_cpp_test test)
   add_executable (${test} src/${test}.cpp)
-  target_link_libraries (${test} qpid-proton-cpp)
+  target_link_libraries (${test} qpid-proton-cpp ${PLATFORM_LIBS})
   if (CMAKE_SYSTEM_NAME STREQUAL Windows)
     add_test (NAME cpp-${test}
       COMMAND ${env_py}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/0df65cc3/proton-c/bindings/cpp/src/container_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/container_test.cpp 
b/proton-c/bindings/cpp/src/container_test.cpp
index 00c8481..030e03d 100644
--- a/proton-c/bindings/cpp/src/container_test.cpp
+++ b/proton-c/bindings/cpp/src/container_test.cpp
@@ -34,6 +34,12 @@
 #include <cstdio>
 #include <sstream>
 
+#if PN_CPP_SUPPORTS_THREADS
+# include <thread>
+# include <mutex>
+# include <condition_variable>
+#endif
+
 namespace {
 
 std::string make_url(std::string host, int port) {
@@ -230,7 +236,7 @@ struct hang_tester : public proton::messaging_handler {
 
     void on_container_start(proton::container& c) PN_CPP_OVERRIDE {
         listener = c.listen("//:0");
-        c.schedule(proton::duration(250), make_work(&hang_tester::connect, 
this, &c));
+        c.schedule(proton::duration(250), 
proton::make_work(&hang_tester::connect, this, &c));
     }
 
     void on_connection_open(proton::connection& c) PN_CPP_OVERRIDE {
@@ -260,10 +266,89 @@ public:
 
 int test_container_immediate_stop() {
     immediate_stop_tester t;
-    proton::container(t).run();  // will hang
+    proton::container(t).run();  // Should return after on_container_start
+    return 0;
+}
+
+int test_container_pre_stop() {
+    proton::container c;
+    c.stop();
+    c.run();                    // Should return immediately
+    return 0;
+}
+
+
+struct schedule_tester : public proton::messaging_handler {
+    void stop(proton::container* c) { c->stop(); }
+
+    void on_container_start(proton::container& c) PN_CPP_OVERRIDE {
+        c.schedule(proton::duration(250), 
proton::make_work(&schedule_tester::stop, this, &c));
+    }
+};
+
+int test_container_schedule_stop() {
+    schedule_tester tester;
+    proton::container c(tester);
+    c.auto_stop(false);
+    c.run();
     return 0;
 }
 
+
+#if PN_CPP_SUPPORTS_THREADS // Tests that require thread support
+
+class test_mt_handler : public proton::messaging_handler {
+  public:
+    std::mutex lock_;
+    std::condition_variable cond_;
+    std::string str_;
+
+    void set(const std::string& s) {
+        std::lock_guard<std::mutex> l(lock_);
+        str_ = s;
+        cond_.notify_one();
+    }
+
+    std::string wait() {
+        std::unique_lock<std::mutex> l(lock_);
+        while (str_.empty()) cond_.wait(l);
+        std::string s = str_;
+        str_.clear();
+        return s;
+    }
+
+    void on_container_start(proton::container &) PN_CPP_OVERRIDE { 
set("start"); }
+    void on_connection_open(proton::connection &) PN_CPP_OVERRIDE { 
set("open"); }
+};
+
+int test_container_mt_stop_empty() {
+    test_mt_handler th;
+    proton::container c(th);
+    c.auto_stop( false );
+    auto t = std::thread([&]() { c.run(); });
+    ASSERT_EQUAL("start", th.wait());
+    c.stop();
+    t.join();
+    return 0;
+}
+
+int test_container_mt_stop() {
+    test_mt_handler th;
+    proton::container c(th);
+    c.auto_stop(false);
+    auto t = std::thread([&]() { c.run(); });
+    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();
+    return 0;
+}
+
+// FIXME aconway 2018-01-04: test busy stop from other thread
+#endif
+
 } // namespace
 
 int main(int argc, char** argv) {
@@ -276,6 +361,12 @@ int main(int argc, char** argv) {
     RUN_ARGV_TEST(failed, test_container_stop());
     RUN_ARGV_TEST(failed, test_container_schedule_nohang());
     RUN_ARGV_TEST(failed, test_container_immediate_stop());
+    RUN_ARGV_TEST(failed, test_container_pre_stop());
+    RUN_ARGV_TEST(failed, test_container_schedule_stop());
+#if PN_CPP_SUPPORTS_THREADS
+    RUN_ARGV_TEST(failed, test_container_mt_stop_empty());
+    RUN_ARGV_TEST(failed, test_container_mt_stop());
+#endif
     return failed;
 }
 


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

Reply via email to