From: Thomas Markwalder Date: Thu, 13 Feb 2014 19:31:31 +0000 (-0500) Subject: [3329] Automatically intiate sends when starting NameChangeSender X-Git-Tag: bind10-1.2.0beta1-release~45^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff31f7b600ba73988f2177a7a6b502e019a86c35;p=thirdparty%2Fkea.git [3329] Automatically intiate sends when starting NameChangeSender Changed dhcp_ddns::NameChangeSender to kick-start send process if there are messages in the queue when startSending is called. Prior to this it required the queuing of a new message via sendRequest(). --- diff --git a/src/lib/dhcp_ddns/ncr_io.cc b/src/lib/dhcp_ddns/ncr_io.cc index 3c8ef5ad39..8e9e7c95fe 100644 --- a/src/lib/dhcp_ddns/ncr_io.cc +++ b/src/lib/dhcp_ddns/ncr_io.cc @@ -188,6 +188,9 @@ NameChangeSender::startSending(isc::asiolink::IOService& io_service) { // Set our status to sending. setSending(true); + + // If there's any queued already.. we'll start sending. + sendNext(); } void diff --git a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc index 6a9f104b2a..1ae11b21a5 100644 --- a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc +++ b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc @@ -448,6 +448,59 @@ TEST(NameChangeUDPSenderBasicTest, basicSendTests) { EXPECT_EQ(0, sender.getQueueSize()); } +/// @brief Tests that sending gets kick-started if the queue isn't empty +/// when startSending is called. +TEST(NameChangeUDPSenderBasicTest, autoStart) { + isc::asiolink::IOAddress ip_address(TEST_ADDRESS); + isc::asiolink::IOService io_service; + SimpleSendHandler ncr_handler; + + // Tests are based on a list of messages, get the count now. + int num_msgs = sizeof(valid_msgs)/sizeof(char*); + + // Create the sender, setting the queue max equal to the number of + // messages we will have in the list. + NameChangeUDPSender sender(ip_address, SENDER_PORT, ip_address, + LISTENER_PORT, FMT_JSON, ncr_handler, + num_msgs, true); + + // Verify that we can start sending. + EXPECT_NO_THROW(sender.startSending(io_service)); + EXPECT_TRUE(sender.amSending()); + + // Queue up messages. + NameChangeRequestPtr ncr; + for (int i = 0; i < num_msgs; i++) { + ASSERT_NO_THROW(ncr = NameChangeRequest::fromJSON(valid_msgs[i])); + EXPECT_NO_THROW(sender.sendRequest(ncr)); + } + // Make sure queue count is what we expect. + EXPECT_EQ(num_msgs, sender.getQueueSize()); + + // Stop sending. + ASSERT_NO_THROW(sender.stopSending()); + ASSERT_FALSE(sender.amSending()); + + // We should have completed the first message only. + EXPECT_EQ(--num_msgs, sender.getQueueSize()); + + // Restart sending. + EXPECT_NO_THROW(sender.startSending(io_service)); + + // We should be able to loop through remaining messages and send them. + for (int i = num_msgs; i > 0; i--) { + // Make sure select_fd does evaluates to ready via select and + // that ioReady() method agrees. + ASSERT_TRUE(sender.ioReady()); + + // Execute at one ready handler. + ASSERT_NO_THROW(sender.runReadyIO()); + } + + // Verify that the queue is empty. + EXPECT_EQ(0, sender.getQueueSize()); +} + /// @brief Tests NameChangeUDPSender basic send with INADDR_ANY and port 0. TEST(NameChangeUDPSenderBasicTest, anyAddressSend) { isc::asiolink::IOAddress ip_address(TEST_ADDRESS);