Browse Source

[master] Fix test that failed on NetBSD

Was not NetBSD-specific, but the symptom only appeared to show there; you cannot reliably do 2 tcp async_send's without waiting for the completion in between.

Fixed it by writing output to a temporary buffer that includes the TCP length data (we might want to consider allowing MessageRenderer to append to a buffer, btw)
Jelte Jansen 14 years ago
parent
commit
df2502bc7f
1 changed files with 11 additions and 12 deletions
  1. 11 12
      src/lib/resolve/tests/recursive_query_unittest_2.cc

+ 11 - 12
src/lib/resolve/tests/recursive_query_unittest_2.cc

@@ -443,8 +443,10 @@ public:
         setReferralExampleOrg(msg);
 
         // Convert to wire format
-        tcp_send_buffer_->clear();
-        MessageRenderer renderer(*tcp_send_buffer_);
+        // Use a temporary buffer for the dns wire data (we copy it
+        // to the 'real' buffer below)
+        OutputBuffer msg_buf(BUFFER_SIZE);
+        MessageRenderer renderer(msg_buf);
         msg.toWire(renderer);
 
         // Expected next state (when checked) is the UDP query to example.org.
@@ -455,16 +457,13 @@ public:
         expected_ = UDP_EXAMPLE_ORG;
         tcp_cumulative_ = 0;
 
-        // We'll write the message in two parts, the count and the message
-        // itself. This saves having to prepend the count onto the start of a
-        // buffer.  When specifying the send handler, the expected size of the
-        // data written is passed as the first parameter so that the handler
-        // can check it.
-        uint8_t count[2];
-        writeUint16(tcp_send_buffer_->getLength(), count);
-        tcp_socket_.async_send(asio::buffer(count, 2),
-                               boost::bind(&RecursiveQueryTest2::tcpSendHandler, this,
-                                           2, _1, _2));
+        // Unless we go through a callback loop we cannot simply use
+        // async_send() multiple times, so we cannot send the size first
+        // followed by the actual data. We copy them to a new buffer
+        // first
+        tcp_send_buffer_->clear();
+        tcp_send_buffer_->writeUint16(msg_buf.getLength());
+        tcp_send_buffer_->writeData(msg_buf.getData(), msg_buf.getLength());
         tcp_socket_.async_send(asio::buffer(tcp_send_buffer_->getData(),
                                             tcp_send_buffer_->getLength()),
                                boost::bind(&RecursiveQueryTest2::tcpSendHandler, this,