#include <cc/data.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/parsers/dhcp_queue_control_parser.h>
-#include <util/multi_threading_mgr.h>
+#include <testutils/multi_threading_utils.h>
#include <testutils/test_to_element.h>
+#include <util/multi_threading_mgr.h>
#include <gtest/gtest.h>
using namespace isc::data;
EXPECT_EQ("true", queue_control->get("enable-queue")->str());
// Retry with multi-threading.
- ASSERT_NO_THROW(MultiThreadingMgr::instance().setMode(true));
- EXPECT_TRUE(MultiThreadingMgr::instance().getMode());
- try {
- queue_control = parser.parse(config_elems);
- MultiThreadingMgr::instance().setMode(false);
- } catch (const std::exception& ex) {
- MultiThreadingMgr::instance().setMode(false);
- FAIL() << "parser threw an exception: " << ex.what();
- }
+ MultiThreadingTest mt(true);
+ ASSERT_TRUE(MultiThreadingMgr::instance().getMode());
+ ASSERT_NO_THROW(queue_control = parser.parse(config_elems));
ASSERT_TRUE(queue_control);
ASSERT_TRUE(queue_control->get("enable-queue"));
EXPECT_EQ("false", queue_control->get("enable-queue")->str());
#include <dhcpsrv/host_data_source_factory.h>
#include <mysql/mysql_connection.h>
#include <mysql/testutils/mysql_schema.h>
+#include <testutils/multi_threading_utils.h>
#include <util/multi_threading_mgr.h>
#include <gtest/gtest.h>
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::data;
+using namespace isc::test;
using namespace isc::util;
using namespace std;
/// opened: the fixtures assume that and check basic operations.
TEST(MySqlHostDataSource, OpenDatabaseMultiThreading) {
// Enable Multi-Threading.
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Schema needs to be created for the test to work.
destroyMySQLSchema();
/// @brief This test verifies that database backend can operate in Read-Only mode.
TEST_F(MySqlHostDataSourceTest, testReadOnlyDatabaseMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testReadOnlyDatabase(MYSQL_VALID_TYPE);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by IPv4
/// address. Host uses hw address as identifier.
TEST_F(MySqlHostDataSourceTest, basic4HWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasic4(Host::IDENT_HWADDR);
}
/// @brief Verifies that IPv4 host reservation with options can have a the global
/// subnet id value
TEST_F(MySqlHostDataSourceTest, globalSubnetId4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGlobalSubnetId4();
}
/// @brief Verifies that IPv6 host reservation with options can have a the global
/// subnet id value
TEST_F(MySqlHostDataSourceTest, globalSubnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGlobalSubnetId6();
}
/// @brief Verifies that IPv4 host reservation with options can have a max value
/// for dhcp4_subnet id
TEST_F(MySqlHostDataSourceTest, maxSubnetId4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxSubnetId4();
}
/// @brief Verifies that IPv6 host reservation with options can have a max value
/// for dhcp6_subnet id
TEST_F(MySqlHostDataSourceTest, maxSubnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxSubnetId6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
TEST_F(MySqlHostDataSourceTest, getAll4BySubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAll4();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
TEST_F(MySqlHostDataSourceTest, getAll6BySubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAll6();
}
/// @brief Verifies that host reservations with the same hostname can be retrieved
TEST_F(MySqlHostDataSourceTest, getAllbyHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostname();
}
/// @brief Verifies that IPv4 host reservations with the same hostname and in
/// the same subnet can be retrieved
TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostnameSubnet4();
}
/// @brief Verifies that IPv6 host reservations with the same hostname and in
/// the same subnet can be retrieved
TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostnameSubnet6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages.
TEST_F(MySqlHostDataSourceTest, getPage4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage4();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages.
TEST_F(MySqlHostDataSourceTest, getPage6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages without truncation from the limit.
TEST_F(MySqlHostDataSourceTest, getPageLimit4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPageLimit4(Host::IDENT_DUID);
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages without truncation from the limit.
TEST_F(MySqlHostDataSourceTest, getPageLimit6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPageLimit6(Host::IDENT_HWADDR);
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages even with multiple subnets.
TEST_F(MySqlHostDataSourceTest, getPage4SubnetsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage4Subnets();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages even with multiple subnets.
TEST_F(MySqlHostDataSourceTest, getPage6SubnetsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage6Subnets();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by IPv4
/// address. Host uses client-id (DUID) as identifier.
TEST_F(MySqlHostDataSourceTest, basic4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasic4(Host::IDENT_DUID);
}
/// @brief Test verifies that multiple hosts can be added and later retrieved by their
/// reserved IPv4 address. This test uses HW addresses as identifiers.
TEST_F(MySqlHostDataSourceTest, getByIPv4HWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv4(Host::IDENT_HWADDR);
}
/// @brief Test verifies that multiple hosts can be added and later retrieved by their
/// reserved IPv4 address. This test uses client-id (DUID) as identifiers.
TEST_F(MySqlHostDataSourceTest, getByIPv4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv4(Host::IDENT_DUID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// hardware address.
TEST_F(MySqlHostDataSourceTest, get4ByHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_HWADDR);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// DUID.
TEST_F(MySqlHostDataSourceTest, get4ByDUIDMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_DUID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// circuit id.
TEST_F(MySqlHostDataSourceTest, get4ByCircuitIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_CIRCUIT_ID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// client-id.
TEST_F(MySqlHostDataSourceTest, get4ByClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_CLIENT_ID);
}
/// @brief Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHWAddrNotClientId();
}
/// @brief Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testClientIdNotHWAddr();
}
/// @brief Test verifies if a host with FQDN hostname can be stored and later retrieved.
TEST_F(MySqlHostDataSourceTest, hostnameFQDNMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("foo.example.org", 1);
}
/// @brief Test verifies if 100 hosts with unique FQDN hostnames can be stored and later
/// retrieved.
TEST_F(MySqlHostDataSourceTest, hostnameFQDN100MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("foo.example.org", 100);
}
/// @brief Test verifies if a host without any hostname specified can be stored and later
/// retrieved.
TEST_F(MySqlHostDataSourceTest, noHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("", 1);
}
/// @brief Test verifies if a host with user context can be stored and later retrieved.
TEST_F(MySqlHostDataSourceTest, usercontextMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testUserContext(Element::fromJSON(comment));
}
/// @brief Test verifies if the hardware or client-id query can match hardware address.
TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
/// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
/// be discussed.
///
/// @brief Test verifies if the hardware or client-id query can match client-id.
TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
/// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
/// be discussed.
///
/// @brief Test verifies that host with IPv6 address and DUID can be added and
/// later retrieved by IPv6 address.
TEST_F(MySqlHostDataSourceTest, get6AddrWithDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_DUID, false);
}
/// @brief Test verifies that host with IPv6 address and HWAddr can be added and
/// later retrieved by IPv6 address.
TEST_F(MySqlHostDataSourceTest, get6AddrWithHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_HWADDR, false);
}
/// @brief Test verifies that host with IPv6 prefix and DUID can be added and
/// later retrieved by IPv6 prefix.
TEST_F(MySqlHostDataSourceTest, get6PrefixWithDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_DUID, true);
}
/// @brief Test verifies that host with IPv6 prefix and HWAddr can be added and
/// later retrieved by IPv6 prefix.
TEST_F(MySqlHostDataSourceTest, get6PrefixWithHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_HWADDR, true);
}
/// @brief Test verifies that host with IPv6 prefix reservation can be retrieved
/// by subnet id and prefix value.
TEST_F(MySqlHostDataSourceTest, get6SubnetPrefixMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetBySubnetIPv6();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// hardware address.
TEST_F(MySqlHostDataSourceTest, get6ByHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet6ByHWAddr();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// client identifier.
TEST_F(MySqlHostDataSourceTest, get6ByClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet6ByClientId();
}
/// @brief Test verifies if a host reservation can be stored with both IPv6 address and
/// prefix.
TEST_F(MySqlHostDataSourceTest, addr6AndPrefixMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddr6AndPrefix();
}
/// @brief Tests if host with multiple IPv6 reservations can be added and then
/// retrieved correctly. Test checks reservations comparing.
TEST_F(MySqlHostDataSourceTest, multipleReservationsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleReservations();
}
/// @brief Tests if compareIPv6Reservations() method treats same pool of reservations
/// but added in different order as equal.
TEST_F(MySqlHostDataSourceTest, multipleReservationsDifferentOrderMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleReservationsDifferentOrder();
}
/// @brief Test that multiple client classes for IPv4 can be inserted and
/// retrieved for a given host reservation.
TEST_F(MySqlHostDataSourceTest, multipleClientClasses4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClasses4();
}
/// @brief Test that multiple client classes for IPv6 can be inserted and
/// retrieved for a given host reservation.
TEST_F(MySqlHostDataSourceTest, multipleClientClasses6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClasses6();
}
/// @brief Test that multiple client classes for both IPv4 and IPv6 can
/// be inserted and retrieved for a given host reservation.
TEST_F(MySqlHostDataSourceTest, multipleClientClassesBothMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClassesBoth();
}
/// hardware address), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them all correctly.
TEST_F(MySqlHostDataSourceTest, multipleSubnetsHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleSubnets(10, Host::IDENT_HWADDR);
}
/// client-identifier), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them correctly.
TEST_F(MySqlHostDataSourceTest, multipleSubnetsClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleSubnets(10, Host::IDENT_DUID);
}
/// Insert 10 host reservations for different subnets. Make sure that
/// get6(subnet-id, ...) calls return correct reservation.
TEST_F(MySqlHostDataSourceTest, subnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testSubnetId6(10, Host::IDENT_HWADDR);
}
/// verify that the second and following attempts will throw exceptions.
/// Hosts with same DUID.
TEST_F(MySqlHostDataSourceTest, addDuplicate6WithDUIDMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate6WithSameDUID();
}
/// verify that the second and following attempts will throw exceptions.
/// Hosts with same HWAddr.
TEST_F(MySqlHostDataSourceTest, addDuplicate6WithHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate6WithSameHWAddr();
}
/// follows: try to add multiple instances of the same host reservation and
/// verify that the second and following attempts will throw exceptions.
TEST_F(MySqlHostDataSourceTest, addDuplicate4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate4();
}
/// @brief This test verifies that DHCPv4 options can be inserted in a binary format
/// and retrieved from the MySQL host database.
TEST_F(MySqlHostDataSourceTest, optionsReservations4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations4(false, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv6 options can be inserted in a binary format
/// and retrieved from the MySQL host database.
TEST_F(MySqlHostDataSourceTest, optionsReservations6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations6(false, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv4 and DHCPv6 options can be inserted in a
/// binary format and retrieved with a single query to the database.
TEST_F(MySqlHostDataSourceTest, optionsReservations46MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testOptionsReservations46(false);
}
/// @brief This test verifies that DHCPv4 options can be inserted in a textual format
/// and retrieved from the MySQL host database.
TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations4(true, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv6 options can be inserted in a textual format
/// and retrieved from the MySQL host database.
TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations6(true, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv4 and DHCPv6 options can be inserted in a
/// textual format and retrieved with a single query to the database.
TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations46MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testOptionsReservations46(true);
}
/// into the database. The failure to insert host information at
/// any stage should cause the whole transaction to be rolled back.
TEST_F(MySqlHostDataSourceTest, testAddRollbackMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Make sure we have the pointer to the host data source.
ASSERT_TRUE(hdsptr_);
/// @brief This test checks that siaddr, sname, file fields can be retrieved
/// from a database for a host.
TEST_F(MySqlHostDataSourceTest, messageFieldsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMessageFields4();
}
/// @brief Check that delete(subnet-id, addr4) works.
TEST_F(MySqlHostDataSourceTest, deleteByAddr4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteByAddr4();
}
/// @brief Check that delete(subnet4-id, identifier-type, identifier) works.
TEST_F(MySqlHostDataSourceTest, deleteById4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById4();
}
/// @brief Check that delete(subnet4-id, identifier-type, identifier) works,
/// even when options are present.
TEST_F(MySqlHostDataSourceTest, deleteById4OptionsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById4Options();
}
/// @brief Check that delete(subnet6-id, identifier-type, identifier) works.
TEST_F(MySqlHostDataSourceTest, deleteById6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById6();
}
/// @brief Check that delete(subnet6-id, identifier-type, identifier) works,
/// even when options are present.
TEST_F(MySqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById6Options();
}
/// @brief Tests that multiple reservations without IPv4 addresses can be
/// specified within a subnet.
TEST_F(MySqlHostDataSourceTest, testMultipleHostsNoAddress4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleHostsNoAddress4();
}
/// @brief Tests that multiple hosts can be specified within an IPv6 subnet.
TEST_F(MySqlHostDataSourceTest, testMultipleHosts6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleHosts6();
}
#include <exceptions/exceptions.h>
#include <mysql/mysql_connection.h>
#include <mysql/testutils/mysql_schema.h>
+#include <testutils/multi_threading_utils.h>
#include <util/multi_threading_mgr.h>
#include <gtest/gtest.h>
using namespace isc::db::test;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
+using namespace isc::test;
using namespace isc::util;
using namespace std;
/// @brief Check that database can be opened with Multi-Threading
TEST(MySqlOpenTest, OpenDatabaseMultiThreading) {
// Enable Multi-Threading.
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Schema needs to be created for the test to work.
createMySQLSchema(true);
// Tidy up after the test
destroyMySQLSchema(true);
LeaseMgrFactory::destroy();
-
- // Disable Multi-Threading.
- MultiThreadingMgr::instance().setMode(false);
}
/// @brief Check the getType() method
/// @brief Basic Lease4 Checks
TEST_F(MySqlLeaseMgrTest, basicLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasicLease4();
}
/// @brief Check that Lease4 code safely handles invalid dates.
TEST_F(MySqlLeaseMgrTest, maxDate4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxDate4();
}
/// @brief Lease4 update tests
TEST_F(MySqlLeaseMgrTest, updateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testUpdateLease4();
}
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testConcurrentUpdateLease4();
}
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddr1();
}
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddr2();
}
/// @brief Get lease4 by hardware address (2)
TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSize();
}
/// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSubnetId();
}
/// @brief Get lease4 by hardware address and subnet ID (2)
TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSubnetIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSubnetIdSize();
}
/// @brief This test was derived from memfile.
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientId();
}
/// @brief Check GetLease4 methods - access by Client ID
TEST_F(MySqlLeaseMgrTest, getLease4ClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientId2();
}
/// @brief Get Lease4 by client ID (2)
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientIdSize();
}
/// @brief Check GetLease4 methods - access by Client ID & Subnet ID
TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientIdSubnetId();
}
/// @brief This test checks that all IPv4 leases for a specified subnet id are returned.
TEST_F(MySqlLeaseMgrTest, getLeases4SubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4SubnetId();
}
/// @brief This test checks that all IPv4 leases with a specified hostname are returned.
TEST_F(MySqlLeaseMgrTest, getLeases4HostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4Hostname();
}
/// @brief This test checks that all IPv4 leases are returned.
TEST_F(MySqlLeaseMgrTest, getLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4();
}
/// @brief Test that a range of IPv4 leases is returned with paging.
TEST_F(MySqlLeaseMgrTest, getLeases4PagedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4Paged();
}
/// @brief This test checks that all IPv6 leases for a specified subnet id are returned.
TEST_F(MySqlLeaseMgrTest, getLeases6SubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6SubnetId();
}
/// @brief This test checks that all IPv6 leases with a specified hostname are returned.
TEST_F(MySqlLeaseMgrTest, getLeases6HostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Hostname();
}
/// @brief This test checks that all IPv6 leases are returned.
TEST_F(MySqlLeaseMgrTest, getLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6();
}
/// @brief Test that a range of IPv6 leases is returned with paging.
TEST_F(MySqlLeaseMgrTest, getLeases6PagedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Paged();
}
/// @brief Basic Lease4 Checks
TEST_F(MySqlLeaseMgrTest, lease4NullClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease4NullClientId();
}
/// @brief Verify that too long hostname for Lease4 is not accepted.
TEST_F(MySqlLeaseMgrTest, lease4InvalidHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease4InvalidHostname();
}
/// @brief Check that the expired DHCPv4 leases can be retrieved.
TEST_F(MySqlLeaseMgrTest, getExpiredLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetExpiredLeases4();
}
/// @brief Check that expired reclaimed DHCPv4 leases are removed.
TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteExpiredReclaimedLeases4();
}
/// @brief Test checks whether simple add, get and delete operations
/// are possible on Lease6
TEST_F(MySqlLeaseMgrTest, testAddGetDelete6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddGetDelete6();
}
/// @brief Basic Lease6 Checks
TEST_F(MySqlLeaseMgrTest, basicLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasicLease6();
}
/// @brief Check that Lease6 code safely handles invalid dates.
TEST_F(MySqlLeaseMgrTest, maxDate6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxDate6();
}
/// @brief Verify that too long hostname for Lease6 is not accepted.
TEST_F(MySqlLeaseMgrTest, lease6InvalidHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6InvalidHostname();
}
/// @brief Verify that large IAID values work correctly.
TEST_F(MySqlLeaseMgrTest, leases6LargeIaidCheckMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6LargeIaidCheck();
}
/// @brief Check GetLease6 methods - access by DUID/IAID
TEST_F(MySqlLeaseMgrTest, getLeases6DuidIaidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6DuidIaid();
}
/// @brief Check that the system can cope with a DUID of allowed size.
TEST_F(MySqlLeaseMgrTest, getLeases6DuidSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6DuidSize();
}
/// @brief Check that getLease6 methods discriminate by lease type.
TEST_F(MySqlLeaseMgrTest, lease6LeaseTypeCheckMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6LeaseTypeCheck();
}
/// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease6DuidIaidSubnetId();
}
/// @brief Test checks that getLease6() works with different DUID sizes
TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease6DuidIaidSubnetIdSize();
}
/// @brief check leases could be retrieved by DUID
TEST_F(MySqlLeaseMgrTest, getLeases6DuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Duid();
}
/// @brief Lease6 update tests
TEST_F(MySqlLeaseMgrTest, updateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testUpdateLease6();
}
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testConcurrentUpdateLease6();
}
/// @brief DHCPv4 Lease recreation tests
TEST_F(MySqlLeaseMgrTest, testRecreateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecreateLease4();
}
/// @brief DHCPv6 Lease recreation tests
TEST_F(MySqlLeaseMgrTest, testRecreateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecreateLease6();
}
/// @brief Checks that null DUID is not allowed.
TEST_F(MySqlLeaseMgrTest, nullDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testNullDuid();
}
/// @brief Tests whether MySQL can store and retrieve hardware addresses
TEST_F(MySqlLeaseMgrTest, testLease6MacMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6MAC();
}
/// @brief Tests whether MySQL can store and retrieve hardware addresses
TEST_F(MySqlLeaseMgrTest, testLease6HWTypeAndSourceMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6HWTypeAndSource();
}
/// @brief Check that the expired DHCPv6 leases can be retrieved.
TEST_F(MySqlLeaseMgrTest, getExpiredLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetExpiredLeases6();
}
/// @brief Check that expired reclaimed DHCPv6 leases are removed.
TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteExpiredReclaimedLeases6();
}
/// @brief Verifies that IPv4 lease statistics can be recalculated.
TEST_F(MySqlLeaseMgrTest, recountLeaseStats4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecountLeaseStats4();
}
/// @brief Verifies that IPv6 lease statistics can be recalculated.
TEST_F(MySqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecountLeaseStats6();
}
/// @brief Tests that leases from specific subnet can be removed.
TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testWipeLeases4();
}
/// @brief Tests that leases from specific subnet can be removed.
TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testWipeLeases6();
}
/// @brief Verifies that db lost callback is not invoked on an open failure
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailure) {
- MultiThreadingMgr::instance().setMode(false);
+ MultiThreadingTest mt(false);
testNoCallbackOnOpenFailure();
}
/// @brief Verifies that db lost callback is not invoked on an open failure
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailureMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testNoCallbackOnOpenFailure();
}
/// @brief Verifies that loss of connectivity to MySQL is handled correctly.
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testDbLostCallback) {
- MultiThreadingMgr::instance().setMode(false);
+ MultiThreadingTest mt(false);
testDbLostCallback();
}
/// @brief Verifies that loss of connectivity to MySQL is handled correctly.
TEST_F(MySQLLeaseMgrDbLostCallbackTest, testDbLostCallbackMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDbLostCallback();
}
/// @brief Tests v4 lease stats query variants.
TEST_F(MySqlLeaseMgrTest, leaseStatsQuery4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQuery4();
}
/// @brief Tests v6 lease stats query variants.
TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQuery6();
}
/// @brief Tests v4 lease stats to be attributed to the wrong subnet.
TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQueryAttribution4();
}
/// @brief Tests v6 lease stats to be attributed to the wrong subnet.
TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQueryAttribution6();
}
#include <pgsql/pgsql_connection.h>
#include <pgsql/testutils/pgsql_schema.h>
#include <util/multi_threading_mgr.h>
+#include <testutils/multi_threading_utils.h>
#include <gtest/gtest.h>
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::data;
+using namespace isc::test;
using namespace isc::util;
using namespace std;
/// opened: the fixtures assume that and check basic operations.
TEST(PgSqlHostDataSource, OpenDatabaseMultiThreading) {
// Enable Multi-Threading.
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Schema needs to be created for the test to work.
destroyPgSQLSchema();
/// as a system test.
TEST(PgSqlHostDataSource, NoCallbackOnOpenFailMultiThreading) {
// Enable Multi-Threading.
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Schema needs to be created for the test to work.
destroyPgSQLSchema();
/// @brief This test verifies that database backend can operate in Read-Only mode.
TEST_F(PgSqlHostDataSourceTest, testReadOnlyDatabaseMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testReadOnlyDatabase(PGSQL_VALID_TYPE);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by IPv4
/// address. Host uses hw address as identifier.
TEST_F(PgSqlHostDataSourceTest, basic4HWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasic4(Host::IDENT_HWADDR);
}
/// @brief Verifies that IPv4 host reservation with options can have a the global
/// subnet id value
TEST_F(PgSqlHostDataSourceTest, globalSubnetId4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGlobalSubnetId4();
}
/// @brief Verifies that IPv6 host reservation with options can have a the global
/// subnet id value
TEST_F(PgSqlHostDataSourceTest, globalSubnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGlobalSubnetId6();
}
/// @brief Verifies that IPv4 host reservation with options can have a max value
/// for dhcp4_subnet id
TEST_F(PgSqlHostDataSourceTest, maxSubnetId4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxSubnetId4();
}
/// @brief Verifies that IPv6 host reservation with options can have a max value
/// for dhcp6_subnet id
TEST_F(PgSqlHostDataSourceTest, maxSubnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxSubnetId6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
TEST_F(PgSqlHostDataSourceTest, getAll4BySubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAll4();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
TEST_F(PgSqlHostDataSourceTest, getAll6BySubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAll6();
}
/// @brief Verifies that host reservations with the same hostname can be retrieved
TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostname();
}
/// @brief Verifies that IPv4 host reservations with the same hostname and in
/// the same subnet can be retrieved
TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostnameSubnet4();
}
/// @brief Verifies that IPv6 host reservations with the same hostname and in
/// the same subnet can be retrieved
TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetAllbyHostnameSubnet6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages.
TEST_F(PgSqlHostDataSourceTest, getPage4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage4();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages.
TEST_F(PgSqlHostDataSourceTest, getPage6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage6();
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages without truncation from the limit.
TEST_F(PgSqlHostDataSourceTest, getPageLimit4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPageLimit4(Host::IDENT_DUID);
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages without truncation from the limit.
TEST_F(PgSqlHostDataSourceTest, getPageLimit6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPageLimit6(Host::IDENT_HWADDR);
}
/// @brief Verifies that IPv4 host reservations in the same subnet can be retrieved
/// by pages even with multiple subnets.
TEST_F(PgSqlHostDataSourceTest, getPage4SubnetsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage4Subnets();
}
/// @brief Verifies that IPv6 host reservations in the same subnet can be retrieved
/// by pages even with multiple subnets.
TEST_F(PgSqlHostDataSourceTest, getPage6SubnetsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetPage6Subnets();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by IPv4
/// address. Host uses client-id (DUID) as identifier.
TEST_F(PgSqlHostDataSourceTest, basic4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasic4(Host::IDENT_DUID);
}
/// @brief Test verifies that multiple hosts can be added and later retrieved by their
/// reserved IPv4 address. This test uses HW addresses as identifiers.
TEST_F(PgSqlHostDataSourceTest, getByIPv4HWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv4(Host::IDENT_HWADDR);
}
/// @brief Test verifies that multiple hosts can be added and later retrieved by their
/// reserved IPv4 address. This test uses client-id (DUID) as identifiers.
TEST_F(PgSqlHostDataSourceTest, getByIPv4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv4(Host::IDENT_DUID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// hardware address.
TEST_F(PgSqlHostDataSourceTest, get4ByHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_HWADDR);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// DUID.
TEST_F(PgSqlHostDataSourceTest, get4ByDUIDMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_DUID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// circuit id.
TEST_F(PgSqlHostDataSourceTest, get4ByCircuitIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_CIRCUIT_ID);
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// client-id.
TEST_F(PgSqlHostDataSourceTest, get4ByClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet4ByIdentifier(Host::IDENT_CLIENT_ID);
}
/// @brief Test verifies if hardware address and client identifier are not confused.
TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHWAddrNotClientId();
}
/// @brief Test verifies if hardware address and client identifier are not confused.
TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testClientIdNotHWAddr();
}
/// @brief Test verifies if a host with FQDN hostname can be stored and later retrieved.
TEST_F(PgSqlHostDataSourceTest, hostnameFQDNMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("foo.example.org", 1);
}
/// @brief Test verifies if 100 hosts with unique FQDN hostnames can be stored and later
/// retrieved.
TEST_F(PgSqlHostDataSourceTest, hostnameFQDN100MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("foo.example.org", 100);
}
/// @brief Test verifies if a host without any hostname specified can be stored and later
/// retrieved.
TEST_F(PgSqlHostDataSourceTest, noHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testHostname("", 1);
}
/// @brief Test verifies if a host with user context can be stored and later retrieved.
TEST_F(PgSqlHostDataSourceTest, usercontextMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testUserContext(Element::fromJSON(comment));
}
/// @brief Test verifies if the hardware or client-id query can match hardware address.
TEST_F(PgSqlHostDataSourceTest, DISABLED_hwaddrOrClientId1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
/// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
/// be discussed.
///
/// @brief Test verifies if the hardware or client-id query can match client-id.
TEST_F(PgSqlHostDataSourceTest, DISABLED_hwaddrOrClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
/// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
/// be discussed.
///
/// @brief Test verifies that host with IPv6 address and DUID can be added and
/// later retrieved by IPv6 address.
TEST_F(PgSqlHostDataSourceTest, get6AddrWithDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_DUID, false);
}
/// @brief Test verifies that host with IPv6 address and HWAddr can be added and
/// later retrieved by IPv6 address.
TEST_F(PgSqlHostDataSourceTest, get6AddrWithHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_HWADDR, false);
}
/// @brief Test verifies that host with IPv6 prefix and DUID can be added and
/// later retrieved by IPv6 prefix.
TEST_F(PgSqlHostDataSourceTest, get6PrefixWithDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_DUID, true);
}
/// @brief Test verifies that host with IPv6 prefix and HWAddr can be added and
/// later retrieved by IPv6 prefix.
TEST_F(PgSqlHostDataSourceTest, get6PrefixWithHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetByIPv6(Host::IDENT_HWADDR, true);
}
/// @brief Test verifies that host with IPv6 prefix reservation can be retrieved
/// by subnet id and prefix value.
TEST_F(PgSqlHostDataSourceTest, get6SubnetPrefixMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetBySubnetIPv6();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// hardware address.
TEST_F(PgSqlHostDataSourceTest, get6ByHWaddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet6ByHWAddr();
}
/// @brief Test verifies if a host reservation can be added and later retrieved by
/// client identifier.
TEST_F(PgSqlHostDataSourceTest, get6ByClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGet6ByClientId();
}
/// @brief Test verifies if a host reservation can be stored with both IPv6 address and
/// prefix.
TEST_F(PgSqlHostDataSourceTest, addr6AndPrefixMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddr6AndPrefix();
}
/// @brief Tests if host with multiple IPv6 reservations can be added and then
/// retrieved correctly. Test checks reservations comparing.
TEST_F(PgSqlHostDataSourceTest, multipleReservationsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleReservations();
}
/// @brief Tests if compareIPv6Reservations() method treats same pool of reservations
/// but added in different order as equal.
TEST_F(PgSqlHostDataSourceTest, multipleReservationsDifferentOrderMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleReservationsDifferentOrder();
}
/// @brief Test that multiple client classes for IPv4 can be inserted and
/// retrieved for a given host reservation.
TEST_F(PgSqlHostDataSourceTest, multipleClientClasses4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClasses4();
}
/// @brief Test that multiple client classes for IPv6 can be inserted and
/// retrieved for a given host reservation.
TEST_F(PgSqlHostDataSourceTest, multipleClientClasses6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClasses6();
}
/// @brief Test that multiple client classes for both IPv4 and IPv6 can
/// be inserted and retrieved for a given host reservation.
TEST_F(PgSqlHostDataSourceTest, multipleClientClassesBothMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleClientClassesBoth();
}
/// hardware address), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them all correctly.
TEST_F(PgSqlHostDataSourceTest, multipleSubnetsHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleSubnets(10, Host::IDENT_HWADDR);
}
/// client-identifier), but for different subnets (different subnet-ids).
/// Make sure that getAll() returns them correctly.
TEST_F(PgSqlHostDataSourceTest, multipleSubnetsClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleSubnets(10, Host::IDENT_DUID);
}
/// Insert 10 host reservations for different subnets. Make sure that
/// get6(subnet-id, ...) calls return correct reservation.
TEST_F(PgSqlHostDataSourceTest, subnetId6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testSubnetId6(10, Host::IDENT_HWADDR);
}
/// verify that the second and following attempts will throw exceptions.
/// Hosts with same DUID.
TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithDUIDMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate6WithSameDUID();
}
/// verify that the second and following attempts will throw exceptions.
/// Hosts with same HWAddr.
TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithHWAddrMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate6WithSameHWAddr();
}
/// follows: try to add multiple instances of the same host reservation and
/// verify that the second and following attempts will throw exceptions.
TEST_F(PgSqlHostDataSourceTest, addDuplicate4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddDuplicate4();
}
/// @brief This test verifies that DHCPv4 options can be inserted in a binary format
/// and retrieved from the PostgreSQL host database.
TEST_F(PgSqlHostDataSourceTest, optionsReservations4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations4(false, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv6 options can be inserted in a binary format
/// and retrieved from the PostgreSQL host database.
TEST_F(PgSqlHostDataSourceTest, optionsReservations6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations6(false, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv4 and DHCPv6 options can be inserted in a
/// binary format and retrieved with a single query to the database.
TEST_F(PgSqlHostDataSourceTest, optionsReservations46MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testOptionsReservations46(false);
}
/// @brief This test verifies that DHCPv4 options can be inserted in a textual format
/// and retrieved from the PostgreSQL host database.
TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations4(true, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv6 options can be inserted in a textual format
/// and retrieved from the PostgreSQL host database.
TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
string comment = "{ \"comment\": \"a host reservation\" }";
testOptionsReservations6(true, Element::fromJSON(comment));
}
/// @brief This test verifies that DHCPv4 and DHCPv6 options can be inserted in a
/// textual format and retrieved with a single query to the database.
TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations46MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testOptionsReservations46(true);
}
/// into the database. The failure to insert host information at
/// any stage should cause the whole transaction to be rolled back.
TEST_F(PgSqlHostDataSourceTest, testAddRollbackMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Make sure we have the pointer to the host data source.
ASSERT_TRUE(hdsptr_);
/// @brief This test checks that siaddr, sname, file fields can be retrieved
/// from a database for a host.
TEST_F(PgSqlHostDataSourceTest, messageFieldsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMessageFields4();
}
/// @brief Check that delete(subnet-id, addr4) works.
TEST_F(PgSqlHostDataSourceTest, deleteByAddr4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteByAddr4();
}
/// @brief Check that delete(subnet4-id, identifier-type, identifier) works.
TEST_F(PgSqlHostDataSourceTest, deleteById4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById4();
}
/// @brief Check that delete(subnet4-id, identifier-type, identifier) works,
/// even when options are present.
TEST_F(PgSqlHostDataSourceTest, deleteById4OptionsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById4Options();
}
/// @brief Check that delete(subnet6-id, identifier-type, identifier) works.
TEST_F(PgSqlHostDataSourceTest, deleteById6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById6();
}
/// @brief Check that delete(subnet6-id, identifier-type, identifier) works,
/// even when options are present.
TEST_F(PgSqlHostDataSourceTest, deleteById6OptionsMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteById6Options();
}
/// @brief Tests that multiple reservations without IPv4 addresses can be
/// specified within a subnet.
TEST_F(PgSqlHostDataSourceTest, testMultipleHostsNoAddress4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleHostsNoAddress4();
}
/// @brief Tests that multiple hosts can be specified within an IPv6 subnet.
TEST_F(PgSqlHostDataSourceTest, testMultipleHosts6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMultipleHosts6();
}
#include <exceptions/exceptions.h>
#include <pgsql/pgsql_connection.h>
#include <pgsql/testutils/pgsql_schema.h>
+#include <testutils/multi_threading_utils.h>
#include <util/multi_threading_mgr.h>
#include <gtest/gtest.h>
using namespace isc::db::test;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
+using namespace isc::test;
using namespace isc::util;
using namespace std;
/// @brief Check that database can be opened with Multi-Threading
TEST(PgSqlOpenTest, OpenDatabaseMultiThreading) {
// Enable Multi-Threading.
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
// Schema needs to be created for the test to work.
createPgSQLSchema();
// Tidy up after the test
destroyPgSQLSchema();
LeaseMgrFactory::destroy();
-
- // Disable Multi-Threading.
- MultiThreadingMgr::instance().setMode(false);
}
/// @brief Check the getType() method
/// @brief Basic Lease4 Checks
TEST_F(PgSqlLeaseMgrTest, basicLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasicLease4();
}
/// @brief Check that Lease4 code safely handles invalid dates.
TEST_F(PgSqlLeaseMgrTest, maxDate4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxDate4();
}
/// @brief Lease4 update tests
TEST_F(PgSqlLeaseMgrTest, updateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testUpdateLease4();
}
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testConcurrentUpdateLease4();
}
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr1MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddr1();
}
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddr2();
}
/// @brief Get lease4 by hardware address (2)
TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSize();
}
/// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
TEST_F(PgSqlLeaseMgrTest, getLease4HwaddrSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSubnetId();
}
/// @brief Get lease4 by hardware address and subnet ID (2)
TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSubnetIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4HWAddrSubnetIdSize();
}
/// @brief This test was derived from memfile.
TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientId();
}
/// @brief Check GetLease4 methods - access by Client ID
TEST_F(PgSqlLeaseMgrTest, getLease4ClientId2MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientId2();
}
/// @brief Get Lease4 by client ID (2)
TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientIdSize();
}
/// @brief Check GetLease4 methods - access by Client ID & Subnet ID
TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease4ClientIdSubnetId();
}
/// @brief This test checks that all IPv4 leases for a specified subnet id are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases4SubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4SubnetId();
}
/// @brief This test checks that all IPv4 leases with a specified hostname are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases4HostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4Hostname();
}
/// @brief This test checks that all IPv4 leases are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4();
}
/// @brief Test that a range of IPv4 leases is returned with paging.
TEST_F(PgSqlLeaseMgrTest, getLeases4PagedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases4Paged();
}
/// @brief This test checks that all IPv6 leases for a specified subnet id are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6SubnetId();
}
/// @brief This test checks that all IPv6 leases with a specified hostname are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases6HostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Hostname();
}
/// @brief This test checks that all IPv6 leases are returned.
TEST_F(PgSqlLeaseMgrTest, getLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6();
}
/// @brief Test that a range of IPv6 leases is returned with paging.
TEST_F(PgSqlLeaseMgrTest, getLeases6PagedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Paged();
}
/// @brief Basic Lease4 Checks
TEST_F(PgSqlLeaseMgrTest, lease4NullClientIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease4NullClientId();
}
/// @brief Verify that too long hostname for Lease4 is not accepted.
TEST_F(PgSqlLeaseMgrTest, lease4InvalidHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease4InvalidHostname();
}
/// @brief Check that the expired DHCPv4 leases can be retrieved.
TEST_F(PgSqlLeaseMgrTest, getExpiredLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetExpiredLeases4();
}
/// @brief Check that expired reclaimed DHCPv4 leases are removed.
TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteExpiredReclaimedLeases4();
}
/// @brief Test checks whether simple add, get and delete operations
/// are possible on Lease6
TEST_F(PgSqlLeaseMgrTest, testAddGetDelete6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testAddGetDelete6();
}
/// @brief Basic Lease6 Checks
TEST_F(PgSqlLeaseMgrTest, basicLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testBasicLease6();
}
/// @brief Check that Lease6 code safely handles invalid dates.
TEST_F(PgSqlLeaseMgrTest, maxDate6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testMaxDate6();
}
/// @brief Verify that too long hostname for Lease6 is not accepted.
TEST_F(PgSqlLeaseMgrTest, lease6InvalidHostnameMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6InvalidHostname();
}
/// @brief Verify that large IAID values work correctly.
TEST_F(PgSqlLeaseMgrTest, leases6LargeIaidCheckMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6LargeIaidCheck();
}
/// @brief Check GetLease6 methods - access by DUID/IAID
TEST_F(PgSqlLeaseMgrTest, getLeases6DuidIaidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6DuidIaid();
}
/// @brief Check that the system can cope with a DUID of allowed size.
TEST_F(PgSqlLeaseMgrTest, getLeases6DuidSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6DuidSize();
}
/// @brief Check that getLease6 methods discriminate by lease type.
TEST_F(PgSqlLeaseMgrTest, lease6LeaseTypeCheckMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6LeaseTypeCheck();
}
/// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetIdMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease6DuidIaidSubnetId();
}
/// @brief Test checks that getLease6() works with different DUID sizes
TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetIdSizeMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLease6DuidIaidSubnetIdSize();
}
/// @brief check leases could be retrieved by DUID
TEST_F(PgSqlLeaseMgrTest, getLeases6DuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetLeases6Duid();
}
/// @brief Lease6 update tests
TEST_F(PgSqlLeaseMgrTest, updateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testUpdateLease6();
}
///
/// Checks that we are not able to concurrently update a lease in the database.
TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testConcurrentUpdateLease6();
}
/// @brief DHCPv4 Lease recreation tests
TEST_F(PgSqlLeaseMgrTest, testRecreateLease4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecreateLease4();
}
/// @brief DHCPv6 Lease recreation tests
TEST_F(PgSqlLeaseMgrTest, testRecreateLease6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecreateLease6();
}
/// @brief Checks that null DUID is not allowed.
TEST_F(PgSqlLeaseMgrTest, nullDuidMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testNullDuid();
}
/// @brief Tests whether PostgreSQL can store and retrieve hardware addresses
TEST_F(PgSqlLeaseMgrTest, testLease6MacMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6MAC();
}
/// @brief Tests whether PostgreSQL can store and retrieve hardware addresses
TEST_F(PgSqlLeaseMgrTest, testLease6HWTypeAndSourceMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLease6HWTypeAndSource();
}
/// @brief Check that the expired DHCPv6 leases can be retrieved.
TEST_F(PgSqlLeaseMgrTest, getExpiredLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testGetExpiredLeases6();
}
/// @brief Check that expired reclaimed DHCPv6 leases are removed.
TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDeleteExpiredReclaimedLeases6();
}
/// @brief Verifies that IPv4 lease statistics can be recalculated.
TEST_F(PgSqlLeaseMgrTest, recountLeaseStats4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecountLeaseStats4();
}
/// @brief Verifies that IPv6 lease statistics can be recalculated.
TEST_F(PgSqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testRecountLeaseStats6();
}
/// @brief Tests that leases from specific subnet can be removed.
TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testWipeLeases4();
}
/// @brief Tests that leases from specific subnet can be removed.
TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testWipeLeases6();
}
/// @brief Verifies that db lost callback is not invoked on an open failure
TEST_F(PgSqlLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailure) {
- MultiThreadingMgr::instance().setMode(false);
+ MultiThreadingTest mt(false);
testDbLostCallback();
}
/// @brief Verifies that db lost callback is not invoked on an open failure
TEST_F(PgSqlLeaseMgrDbLostCallbackTest, testNoCallbackOnOpenFailureMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDbLostCallback();
}
/// @brief Verifies that loss of connectivity to PostgreSQL is handled correctly.
TEST_F(PgSqlLeaseMgrDbLostCallbackTest, testDbLostCallback) {
- MultiThreadingMgr::instance().setMode(false);
+ MultiThreadingTest mt(false);
testDbLostCallback();
}
/// @brief Verifies that loss of connectivity to PostgreSQL is handled correctly.
TEST_F(PgSqlLeaseMgrDbLostCallbackTest, testDbLostCallbackMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testDbLostCallback();
}
/// @brief Tests v4 lease stats query variants.
TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQuery4();
}
/// @brief Tests v6 lease stats query variants.
TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQuery6();
}
/// @brief Tests v4 lease stats to be attributed to the wrong subnet.
TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution4MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQueryAttribution4();
}
/// @brief Tests v6 lease stats to be attributed to the wrong subnet.
TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution6MultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
testLeaseStatsQueryAttribution6();
}
#include <dhcpsrv/triplet.h>
#include <exceptions/exceptions.h>
#include <testutils/test_to_element.h>
-#include <util/multi_threading_mgr.h>
+#include <testutils/multi_threading_utils.h>
#include <gtest/gtest.h>
#include <cstdint>
using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
-using namespace isc::util;
+using namespace isc::test;
namespace {
// This test verifies that preferred subnet is returned based on the timestamp
// when the subnet was last used and allowed client classes.
TEST(SharedNetwork4Test, getPreferredSubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
SharedNetwork4Ptr network(new SharedNetwork4("frog"));
// Create four subnets.
// Repeat the test for subnet3 being a selected subnet.
preferred = network->getPreferredSubnet(subnet3);
EXPECT_EQ(subnet3->getID(), preferred->getID());
- MultiThreadingMgr::instance().setMode(false);
}
// This test verifies that subnetsIncludeMatchClientId() works as expected.
// This test verifies that preferred subnet is returned based on the timestamp
// when the subnet was last used and allowed client classes.
TEST(SharedNetwork6Test, getPreferredSubnetMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
SharedNetwork6Ptr network(new SharedNetwork6("frog"));
// Create four subnets.
// Repeat the test for subnet3 being a selected subnet.
preferred = network->getPreferredSubnet(subnet3, Lease::TYPE_NA);
EXPECT_EQ(subnet3->getID(), preferred->getID());
- MultiThreadingMgr::instance().setMode(false);
}
// This test verifies that subnetsAllHRGlobal() works as expected.
#include <dhcpsrv/shared_network.h>
#include <dhcpsrv/subnet.h>
#include <exceptions/exceptions.h>
-#include <util/multi_threading_mgr.h>
+#include <testutils/multi_threading_utils.h>
#include <boost/pointer_cast.hpp>
#include <boost/scoped_ptr.hpp>
using namespace isc;
using namespace isc::dhcp;
using namespace isc::asiolink;
-using namespace isc::util;
+using namespace isc::test;
namespace {
// Checks if last allocated address/prefix is stored/retrieved properly
TEST(Subnet4Test, lastAllocatedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
IOAddress addr("192.0.2.17");
IOAddress last("192.0.2.255");
EXPECT_THROW(subnet->setLastAllocated(Lease::TYPE_TA, addr), BadValue);
EXPECT_THROW(subnet->setLastAllocated(Lease::TYPE_TA, addr), BadValue);
EXPECT_THROW(subnet->setLastAllocated(Lease::TYPE_PD, addr), BadValue);
- MultiThreadingMgr::instance().setMode(false);
}
// Checks if the V4 is the only allowed type for Pool4 and if getPool()
// Checks if last allocated address/prefix is stored/retrieved properly
TEST(Subnet6Test, lastAllocatedMultiThreading) {
- MultiThreadingMgr::instance().setMode(true);
+ MultiThreadingTest mt(true);
IOAddress ia("2001:db8:1::1");
IOAddress ta("2001:db8:1::abcd");
IOAddress pd("2001:db8:1::1234:5678");
// No, you can't set the last allocated IPv4 address in IPv6 subnet
EXPECT_THROW(subnet->setLastAllocated(Lease::TYPE_V4, ia), BadValue);
- MultiThreadingMgr::instance().setMode(false);
}
// This test verifies that the IPv4 subnet can be fetched by id.
libkea_testutils_la_SOURCES += unix_control_client.cc unix_control_client.h
libkea_testutils_la_SOURCES += user_context_utils.cc user_context_utils.h
libkea_testutils_la_SOURCES += gtest_utils.h
+libkea_testutils_la_SOURCES += multi_threading_utils.h
libkea_testutils_la_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
libkea_testutils_la_LIBADD = $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
libkea_testutils_la_LIBADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
--- /dev/null
+// Copyright (C) 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef MULTI_THREADING_UTILS_H
+#define MULTI_THREADING_UTILS_H
+
+#include <util/multi_threading_mgr.h>
+
+namespace isc {
+namespace test {
+
+/// @brief A RAII class which disables the multi threading on exit of scope.
+///
+/// Usually the multi threading is disabled by the fixture destructor ot
+/// TearDown but of course this works only when a fixture class is used.
+class MultiThreadingTest {
+public:
+
+ /// @brief Constructor (set multi threading mode).
+ ///
+ /// @param mode The mode to use in the body. Defaults to true / enabled.
+ MultiThreadingTest(bool mode = true) {
+ isc::util::MultiThreadingMgr::instance().setMode(mode);
+ }
+
+ /// @brief Destructor (disable multi threading).
+ ~MultiThreadingTest() {
+ isc::util::MultiThreadingMgr::instance().setMode(false);
+ }
+};
+
+} // end of isc::test namespace
+} // end of isc namespace
+
+#endif // MULTI_THREADING_UTILS_H