Skip to content

Commit

Permalink
PROTON-2748: Raw connection async close tests. 2nd part of pull 402
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffjansen committed Nov 15, 2024
1 parent ecb3431 commit e0fd484
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
4 changes: 2 additions & 2 deletions c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
76 changes: 76 additions & 0 deletions c/tests/raw_connection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand Down Expand Up @@ -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);
}

0 comments on commit e0fd484

Please sign in to comment.