THRIFT-1562 Fix issue with TFramedTransport::readSlow
Patch: Dave Watson
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1325034 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp
index 767e563..bc0529d 100644
--- a/lib/cpp/test/TransportTest.cpp
+++ b/lib/cpp/test/TransportTest.cpp
@@ -561,6 +561,7 @@
BOOST_CHECK_EQUAL(memcmp(rbuf.get(), wbuf.get(), totalSize), 0);
}
+
template <class CoupledTransports>
void test_read_part_available() {
CoupledTransports transports;
@@ -584,6 +585,33 @@
}
template <class CoupledTransports>
+void test_read_part_available_in_chunks() {
+ CoupledTransports transports;
+ BOOST_REQUIRE(transports.in != NULL);
+ BOOST_REQUIRE(transports.out != NULL);
+
+ uint8_t write_buf[16];
+ uint8_t read_buf[16];
+ memset(write_buf, 'a', sizeof(write_buf));
+
+ // Write 10 bytes (in a single frame, for transports that use framing)
+ transports.out->write(write_buf, 10);
+ transports.out->flush();
+
+ // Read 1 byte, to force the transport to read the frame
+ uint32_t bytes_read = transports.in->read(read_buf, 1);
+ BOOST_CHECK_EQUAL(bytes_read, 1);
+
+ // Read more than what is remaining and verify the transport does not block
+ set_trigger(3, transports.out, 1);
+ bytes_read = transports.in->read(read_buf, 10);
+ BOOST_CHECK_EQUAL(numTriggersFired, 0);
+ BOOST_CHECK_EQUAL(bytes_read, 9);
+
+ clear_triggers();
+}
+
+template <class CoupledTransports>
void test_read_partial_midframe() {
CoupledTransports transports;
BOOST_REQUIRE(transports.in != NULL);
@@ -912,6 +940,12 @@
test_read_part_available<CoupledTransports>, name);
suite_->add(tc, expectedFailures);
+ snprintf(name, sizeof(name), "%s::test_read_part_available_in_chunks()",
+ transportName);
+ tc = boost::unit_test::make_test_case(
+ test_read_part_available_in_chunks<CoupledTransports>, name);
+ suite_->add(tc, expectedFailures);
+
snprintf(name, sizeof(name), "%s::test_read_partial_midframe()",
transportName);
tc = boost::unit_test::make_test_case(