Commit 0997ee1b authored by Francis Dupont's avatar Francis Dupont

[#1282] Improved clearParkingLots

parent 30d734f8
......@@ -653,7 +653,7 @@ void Dhcpv4Srv::setPacketStatisticsDefaults() {
}
Dhcpv4Srv::~Dhcpv4Srv() {
// Discard any cached packets or parked packets
// Discard any parked packets
discardPackets();
try {
......@@ -3991,10 +3991,7 @@ int Dhcpv4Srv::getHookIndexLease4Decline() {
}
void Dhcpv4Srv::discardPackets() {
// Clear any packets held by the callhout handle store and
// all parked packets
isc::dhcp::Pkt4Ptr pkt4ptr_empty;
isc::dhcp::getCalloutHandle(pkt4ptr_empty);
// Dump all of our current packets, anything that is mid-stream
HooksManager::clearParkingLots();
}
......
......@@ -440,9 +440,9 @@ public:
NameChangeSender::Result result,
dhcp_ddns::NameChangeRequestPtr& ncr);
/// @brief Discards cached and parked packets
/// Clears the call_handle store and packet parking lots
/// of all packets. Called during reconfigure and shutdown.
/// @brief Discards parked packets
/// Clears the packet parking lots of all packets.
/// Called during reconfigure and shutdown.
void discardPackets();
/// @brief Returns value of the test_send_responses_to_source_ flag.
......
......@@ -260,7 +260,9 @@ void Dhcpv6Srv::setPacketStatisticsDefaults() {
}
Dhcpv6Srv::~Dhcpv6Srv() {
// Discard any parked packets
discardPackets();
try {
stopD2();
} catch(const std::exception& ex) {
......@@ -4181,8 +4183,6 @@ Dhcpv6Srv::requestedInORO(const Pkt6Ptr& query, const uint16_t code) const {
void Dhcpv6Srv::discardPackets() {
// Dump all of our current packets, anything that is mid-stream
isc::dhcp::Pkt6Ptr pkt6ptr_empty;
isc::dhcp::getCalloutHandle(pkt6ptr_empty);
HooksManager::clearParkingLots();
}
......
......@@ -250,9 +250,9 @@ public:
NameChangeSender::Result result,
dhcp_ddns::NameChangeRequestPtr& ncr);
/// @brief Discards cached and parked packets
/// Clears the call_handle store and packet parking lots
/// of all packets. Called during reconfigure and shutdown.
/// @brief Discards parked packets
/// Clears the packet parking lots of all packets.
/// Called during reconfigure and shutdown.
void discardPackets();
protected:
......
......@@ -213,6 +213,8 @@ HooksManager::validateLibraries(const std::vector<std::string>& libraries) {
return (LibraryManagerCollection::validateLibraries(libraries));
}
// Test mode
void
HooksManager::setTestMode(bool mode) {
getHooksManager().test_mode_ = mode;
......
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
......@@ -8,6 +8,7 @@
#include <exceptions/exceptions.h>
#include <hooks/parking_lots.h>
#include <boost/weak_ptr.hpp>
#include <gtest/gtest.h>
#include <string>
......@@ -111,4 +112,45 @@ TEST(ParkingLotTest, drop) {
EXPECT_FALSE(parking_lot_handle->unpark(parked_object));
}
// Test that parked lots can be cleared.
TEST(ParkingLotTest, clear) {
ParkingLotsPtr parking_lots = boost::make_shared<ParkingLots>();
ParkingLotPtr parking_lot = parking_lots->getParkingLotPtr(1234);
ASSERT_TRUE(parking_lot);
ParkingLotHandlePtr parking_lot_handle =
boost::make_shared<ParkingLotHandle>(parking_lot);
boost::shared_ptr<std::string> parked_object =
boost::make_shared<std::string>("foo");
boost::weak_ptr<std::string> weak_parked_object(parked_object);
// Reference object twice to test that clearing the parking lots
// ignores reference counting.
ASSERT_NO_THROW(parking_lot_handle->reference(parked_object));
ASSERT_NO_THROW(parking_lot_handle->reference(parked_object));
// This flag will indicate if the callback has been called.
bool unparked = false;
ASSERT_NO_THROW(parking_lot->park(parked_object, [&unparked] {
unparked = true;
}));
// Drop reference on objects.
parking_lot.reset();
parking_lot_handle.reset();
parked_object.reset();
// The parked object is still alive.
EXPECT_FALSE(weak_parked_object.expired());
// Clear the parking lots.
ASSERT_NO_THROW(parking_lots->clear());
// The callback should not be invoked.
EXPECT_FALSE(unparked);
// The parked object was destroyed.
EXPECT_TRUE(weak_parked_object.expired());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment