You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2021/03/02 04:24:38 UTC
[qpid-proton] 03/03: PROTON-2338:: Added some testing for raw
connection half close
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 2381e1f532756a2b3c02fbaa30965fdd14bb1c18
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue Feb 23 17:14:11 2021 -0500
PROTON-2338:: Added some testing for raw connection half close
Unit test half close
Half close write side in raw_connect when writing final message
---
c/examples/raw_connect.c | 4 +++-
c/examples/raw_echo.c | 6 +++++-
c/tests/raw_connection_test.cpp | 33 ++++++++++++++++++++++++++-------
3 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/c/examples/raw_connect.c b/c/examples/raw_connect.c
index 36f2f71..d380801 100644
--- a/c/examples/raw_connect.c
+++ b/c/examples/raw_connect.c
@@ -143,6 +143,7 @@ static void handle_send(app_data_t* app, pn_event_t* event) {
pn_raw_connection_set_context(c, NULL);
free(cd);
printf("**raw connection disconnected\n");
+ pn_proactor_cancel_timeout(app->proactor);
app->disconnects++;
check_condition(event, pn_raw_connection_condition(c), app);
} break;
@@ -153,7 +154,8 @@ static void handle_send(app_data_t* app, pn_event_t* event) {
if (fgets(line, sizeof(line), stdin)) {
send_message(c, line);
} else {
- /* On end of file wait 2 sec for response */
+ /* On end of file, close for write then wait 2 sec for response */
+ pn_raw_connection_write_close(c);
app->towake = c;
pn_proactor_set_timeout(app->proactor, 2000);
}
diff --git a/c/examples/raw_echo.c b/c/examples/raw_echo.c
index 374ffaa..d47f95b 100644
--- a/c/examples/raw_echo.c
+++ b/c/examples/raw_echo.c
@@ -96,7 +96,11 @@ static void send_message(pn_raw_connection_t *c, const char* msg) {
buffer.capacity = 1024;
buffer.offset = 0;
buffer.size = len;
- pn_raw_connection_write_buffers(c, &buffer, 1);
+ // If message not accepted just throw it away!
+ if (pn_raw_connection_write_buffers(c, &buffer, 1) < 1) {
+ printf("**Couldn't send message: write not accepted**\n");
+ free(buf);
+ }
}
static void recv_message(pn_raw_buffer_t buf) {
diff --git a/c/tests/raw_connection_test.cpp b/c/tests/raw_connection_test.cpp
index 4ad4689..b7ce803 100644
--- a/c/tests/raw_connection_test.cpp
+++ b/c/tests/raw_connection_test.cpp
@@ -530,7 +530,7 @@ TEST_CASE("raw connection") {
// No need buffers event as we already gave buffers
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_EVENT_NONE);
- pni_raw_close(p);
+ pni_raw_write_close(p);
size_t rgiven = pn_raw_connection_take_read_buffers(p, &read[0], rtaken);
REQUIRE(pni_raw_validate(p));
@@ -539,19 +539,35 @@ TEST_CASE("raw connection") {
REQUIRE(pni_raw_validate(p));
CHECK(wgiven==0);
- REQUIRE(pn_raw_connection_is_read_closed(p));
REQUIRE(pn_raw_connection_is_write_closed(p));
- REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_CLOSED_READ);
- REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_EVENT_NONE);
-
- REQUIRE_FALSE(pni_raw_can_read(p));
REQUIRE(pni_raw_can_write(p));
pni_raw_write(p, fds[0], snd, set_write_error);
REQUIRE(pni_raw_validate(p));
CHECK(write_err == 0);
+ REQUIRE_FALSE(pni_raw_can_write(p));
+
+ REQUIRE(pni_raw_can_read(p));
+ pni_raw_read(p, fds[0], rcv, set_read_error);
+ REQUIRE(pni_raw_validate(p));
+ CHECK(read_err == 0);
+
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_WRITTEN);
+
+ SECTION("Read close after write close") {
+ pni_raw_read_close(p);
+ }
+
+ SECTION("Full close after write close") {
+ // We should be able to fully close here (even if we read close would be more specific)
+ pni_raw_close(p);
+ }
+
+ REQUIRE(pn_raw_connection_is_read_closed(p));
+ REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_CLOSED_READ);
+
+ REQUIRE_FALSE(pni_raw_can_read(p));
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_CLOSED_WRITE);
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_READ);
rgiven = pn_raw_connection_take_read_buffers(p, &read[0], rtaken);
@@ -561,6 +577,10 @@ TEST_CASE("raw connection") {
wgiven = pn_raw_connection_take_written_buffers(p, &written[0], wtaken);
REQUIRE(pni_raw_validate(p));
CHECK(wgiven==wtaken);
+
+ // This should have no affect because we are already read and write closed
+ pni_raw_close(p);
+
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_RAW_CONNECTION_DISCONNECTED);
REQUIRE(pn_event_type(pni_raw_event_next(p)) == PN_EVENT_NONE);
@@ -770,7 +790,6 @@ TEST_CASE("raw connection") {
REQUIRE(pni_raw_validate(p));
CHECK(rgiven > 0);
- CHECK(pn_raw_connection_read_buffers_capacity(p) == rgiven);
CHECK(read[rgiven-1].size == 0);
// At this point we should have read everything - make sure it matches
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org