This is an automated email from the ASF dual-hosted git repository.

cliffjansen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new e0fd4845d PROTON-2748: Raw connection async close tests. 2nd part of 
pull 402
e0fd4845d is described below

commit e0fd4845dc778745ef2244fe46b67edcd289963e
Author: Cliff Jansen <[email protected]>
AuthorDate: Fri Nov 15 11:10:23 2024 -0800

    PROTON-2748: Raw connection async close tests. 2nd part of pull 402
---
 c/tests/CMakeLists.txt                             |  4 +-
 ...e_test.cpp => raw_connection_proactor_test.cpp} |  0
 c/tests/raw_connection_test.cpp                    | 76 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/c/tests/CMakeLists.txt b/c/tests/CMakeLists.txt
index 3bb12a336..1dd884834 100644
--- a/c/tests/CMakeLists.txt
+++ b/c/tests/CMakeLists.txt
@@ -83,8 +83,8 @@ if (CMAKE_CXX_COMPILER)
     target_link_libraries(c-raw-connection-test qpid-proton-core 
${PLATFORM_LIBS} ${PROACTOR_LIBS})
 
     if (PROACTOR_OK STREQUAL "epoll")
-      add_c_test(c-raw-wake-test raw_wake_test.cpp pn_test_proactor.cpp 
$<TARGET_OBJECTS:qpid-proton-proactor-objects>)
-      target_link_libraries(c-raw-wake-test qpid-proton-core ${PLATFORM_LIBS} 
${PROACTOR_LIBS})
+      add_c_test(c-raw-connection-proactor-test 
raw_connection_proactor_test.cpp pn_test_proactor.cpp 
$<TARGET_OBJECTS:qpid-proton-proactor-objects>)
+      target_link_libraries(c-raw-connection-proactor-test qpid-proton-core 
${PLATFORM_LIBS} ${PROACTOR_LIBS})
     endif()
 
     add_c_test(c-ssl-proactor-test pn_test_proactor.cpp ssl_proactor_test.cpp)
diff --git a/c/tests/raw_wake_test.cpp 
b/c/tests/raw_connection_proactor_test.cpp
similarity index 100%
rename from c/tests/raw_wake_test.cpp
rename to c/tests/raw_connection_proactor_test.cpp
diff --git a/c/tests/raw_connection_test.cpp b/c/tests/raw_connection_test.cpp
index 92cc2ad0f..6d8096ad5 100644
--- a/c/tests/raw_connection_test.cpp
+++ b/c/tests/raw_connection_test.cpp
@@ -268,6 +268,31 @@ namespace {
     if (b.bytes) {b.capacity = s; b.size = s;}
     return b;
   }
+
+  bool drain_events_to(pn_raw_connection_t *c, pn_event_type_t target) {
+    while (pn_event_t *e = pni_raw_event_next(c)) {
+      if (pn_event_type(e) == target)
+        return true;
+    }
+    return false;
+  }
+
+  bool drain_events_until_both(pn_raw_connection_t *c, pn_event_type_t 
target1, pn_event_type_t target2) {
+    bool t1 = false; // target 1 seen
+    bool t2 = false;
+    while (pn_event_t *e = pni_raw_event_next(c)) {
+      if (pn_event_type(e) == target1) {
+        t1 = true;
+        if (t2) return true;
+      }
+      if (pn_event_type(e) == target2) {
+        t2 = true;
+        if (t1) return true;
+      }
+    }
+    return false;
+  }
+
 }
 
 char message[] =
@@ -814,3 +839,54 @@ TEST_CASE("raw connection") {
     }
   }
 }
+
+TEST_CASE("raw connection async close") {
+  auto_free<pn_raw_connection_t, free_raw_connection> p(mk_raw_connection());
+
+  REQUIRE(p);
+  CHECK_FALSE(pn_raw_connection_is_read_closed(p));
+  CHECK_FALSE(pn_raw_connection_is_write_closed(p));
+  pni_raw_connected(p);
+  REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_CONNECTED);
+
+  SECTION("Async close only") {
+    // nothing
+  }
+
+  SECTION("Read close then async close") {
+    pni_raw_read_close(p);
+    REQUIRE(drain_events_to(p, PN_RAW_CONNECTION_CLOSED_READ));
+  }
+
+  SECTION("Write close then async close") {
+    pni_raw_write_close(p);
+    REQUIRE(drain_events_to(p, PN_RAW_CONNECTION_CLOSED_WRITE));
+  }
+
+  SECTION("Full close then async close") {
+    pni_raw_close(p);
+    REQUIRE(drain_events_until_both(p, PN_RAW_CONNECTION_CLOSED_READ, 
PN_RAW_CONNECTION_CLOSED_WRITE));
+  }
+
+  pni_raw_async_disconnect(p);
+  CHECK(pn_raw_connection_is_read_closed(p));
+  CHECK(pn_raw_connection_is_write_closed(p));
+
+  SECTION("Async close then read close") {
+    pni_raw_read_close(p);
+    REQUIRE(drain_events_until_both(p, PN_RAW_CONNECTION_CLOSED_READ, 
PN_RAW_CONNECTION_CLOSED_WRITE));
+  }
+
+  SECTION("Async close then write close") {
+    pni_raw_write_close(p);
+    REQUIRE(drain_events_until_both(p, PN_RAW_CONNECTION_CLOSED_READ, 
PN_RAW_CONNECTION_CLOSED_WRITE));
+  }
+
+  SECTION("Async close then full close") {
+    pni_raw_close(p);
+    REQUIRE(drain_events_until_both(p, PN_RAW_CONNECTION_CLOSED_READ, 
PN_RAW_CONNECTION_CLOSED_WRITE));
+  }
+
+  REQUIRE(drain_events_to(p, PN_RAW_CONNECTION_DISCONNECTED));
+  REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_EVENT_NONE);
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to