]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1292] Added RAII MT test
authorFrancis Dupont <fdupont@isc.org>
Sun, 2 Aug 2020 11:30:34 +0000 (13:30 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 5 Aug 2020 09:59:59 +0000 (11:59 +0200)
src/lib/dhcpsrv/tests/dhcp_queue_control_parser_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/shared_network_unittest.cc
src/lib/dhcpsrv/tests/subnet_unittest.cc
src/lib/testutils/Makefile.am
src/lib/testutils/multi_threading_utils.h [new file with mode: 0644]

index 405e56eeb5d45431963a41e75459d8f0c1f065c7..cf3f102bd63826fc57f9405eff7a2eeb4edc1ceb 100644 (file)
@@ -9,8 +9,9 @@
 #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;
@@ -196,15 +197,9 @@ TEST_F(DHCPQueueControlParserTest, multiThreading) {
     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());
index d19b9a2ad358fdb3f3f339f3fcb54e5c89b3ab40..226d07943c06f84f5c626a44a7a03610185544d0 100644 (file)
@@ -17,6 +17,7 @@
 #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>
@@ -34,6 +35,7 @@ using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::data;
+using namespace isc::test;
 using namespace isc::util;
 using namespace std;
 
@@ -245,7 +247,7 @@ TEST(MySqlHostDataSource, OpenDatabase) {
 /// 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();
@@ -374,7 +376,7 @@ TEST_F(MySqlHostDataSourceTest, testReadOnlyDatabase) {
 
 /// @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);
 }
 
@@ -387,7 +389,7 @@ TEST_F(MySqlHostDataSourceTest, basic4HWAddr) {
 /// @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);
 }
 
@@ -400,7 +402,7 @@ TEST_F(MySqlHostDataSourceTest, globalSubnetId4) {
 /// @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();
 }
 
@@ -413,7 +415,7 @@ TEST_F(MySqlHostDataSourceTest, globalSubnetId6) {
 /// @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();
 }
 
@@ -426,7 +428,7 @@ TEST_F(MySqlHostDataSourceTest, maxSubnetId4) {
 /// @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();
 }
 
@@ -439,7 +441,7 @@ TEST_F(MySqlHostDataSourceTest, maxSubnetId6) {
 /// @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();
 }
 
@@ -450,7 +452,7 @@ TEST_F(MySqlHostDataSourceTest, getAll4BySubnet) {
 
 /// @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();
 }
 
@@ -461,7 +463,7 @@ TEST_F(MySqlHostDataSourceTest, getAll6BySubnet) {
 
 /// @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();
 }
 
@@ -472,7 +474,7 @@ TEST_F(MySqlHostDataSourceTest, getAllbyHostname) {
 
 /// @brief Verifies that host reservations with the same hostname can be retrieved
 TEST_F(MySqlHostDataSourceTest, getAllbyHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetAllbyHostname();
 }
 
@@ -485,7 +487,7 @@ TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet4) {
 /// @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();
 }
 
@@ -498,7 +500,7 @@ TEST_F(MySqlHostDataSourceTest, getAllbyHostnameSubnet6) {
 /// @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();
 }
 
@@ -511,7 +513,7 @@ TEST_F(MySqlHostDataSourceTest, getPage4) {
 /// @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();
 }
 
@@ -524,7 +526,7 @@ TEST_F(MySqlHostDataSourceTest, getPage6) {
 /// @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();
 }
 
@@ -537,7 +539,7 @@ TEST_F(MySqlHostDataSourceTest, getPageLimit4) {
 /// @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);
 }
 
@@ -550,7 +552,7 @@ TEST_F(MySqlHostDataSourceTest, getPageLimit6) {
 /// @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);
 }
 
@@ -563,7 +565,7 @@ TEST_F(MySqlHostDataSourceTest, getPage4Subnets) {
 /// @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();
 }
 
@@ -576,7 +578,7 @@ TEST_F(MySqlHostDataSourceTest, getPage6Subnets) {
 /// @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();
 }
 
@@ -589,7 +591,7 @@ TEST_F(MySqlHostDataSourceTest, basic4ClientId) {
 /// @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);
 }
 
@@ -602,7 +604,7 @@ TEST_F(MySqlHostDataSourceTest, getByIPv4HWaddr) {
 /// @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);
 }
 
@@ -615,7 +617,7 @@ TEST_F(MySqlHostDataSourceTest, getByIPv4ClientId) {
 /// @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);
 }
 
@@ -628,7 +630,7 @@ TEST_F(MySqlHostDataSourceTest, get4ByHWaddr) {
 /// @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);
 }
 
@@ -641,7 +643,7 @@ TEST_F(MySqlHostDataSourceTest, get4ByDUID) {
 /// @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);
 }
 
@@ -654,7 +656,7 @@ TEST_F(MySqlHostDataSourceTest, get4ByCircuitId) {
 /// @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);
 }
 
@@ -667,7 +669,7 @@ TEST_F(MySqlHostDataSourceTest, get4ByClientId) {
 /// @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);
 }
 
@@ -678,7 +680,7 @@ TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1) {
 
 /// @brief Test verifies if hardware address and client identifier are not confused.
 TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testHWAddrNotClientId();
 }
 
@@ -689,7 +691,7 @@ TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2) {
 
 /// @brief Test verifies if hardware address and client identifier are not confused.
 TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testClientIdNotHWAddr();
 }
 
@@ -700,7 +702,7 @@ TEST_F(MySqlHostDataSourceTest, hostnameFQDN) {
 
 /// @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);
 }
 
@@ -713,7 +715,7 @@ TEST_F(MySqlHostDataSourceTest, hostnameFQDN100) {
 /// @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);
 }
 
@@ -726,7 +728,7 @@ TEST_F(MySqlHostDataSourceTest, noHostname) {
 /// @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);
 }
 
@@ -738,7 +740,7 @@ TEST_F(MySqlHostDataSourceTest, usercontext) {
 
 /// @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));
 }
@@ -755,7 +757,7 @@ TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId1) {
 
 /// @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.
     ///
@@ -776,7 +778,7 @@ TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId2) {
 
 /// @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.
     ///
@@ -794,7 +796,7 @@ TEST_F(MySqlHostDataSourceTest, get6AddrWithDuid) {
 /// @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);
 }
 
@@ -807,7 +809,7 @@ TEST_F(MySqlHostDataSourceTest, get6AddrWithHWAddr) {
 /// @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);
 }
 
@@ -820,7 +822,7 @@ TEST_F(MySqlHostDataSourceTest, get6PrefixWithDuid) {
 /// @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);
 }
 
@@ -833,7 +835,7 @@ TEST_F(MySqlHostDataSourceTest, get6PrefixWithHWaddr) {
 /// @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);
 }
 
@@ -846,7 +848,7 @@ TEST_F(MySqlHostDataSourceTest, get6SubnetPrefix) {
 /// @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();
 }
 
@@ -859,7 +861,7 @@ TEST_F(MySqlHostDataSourceTest, get6ByHWaddr) {
 /// @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();
 }
 
@@ -872,7 +874,7 @@ TEST_F(MySqlHostDataSourceTest, get6ByClientId) {
 /// @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();
 }
 
@@ -885,7 +887,7 @@ TEST_F(MySqlHostDataSourceTest, addr6AndPrefix) {
 /// @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();
 }
 
@@ -898,7 +900,7 @@ TEST_F(MySqlHostDataSourceTest, multipleReservations) {
 /// @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();
 }
 
@@ -911,7 +913,7 @@ TEST_F(MySqlHostDataSourceTest, multipleReservationsDifferentOrder) {
 /// @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();
 }
 
@@ -924,7 +926,7 @@ TEST_F(MySqlHostDataSourceTest, multipleClientClasses4) {
 /// @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();
 }
 
@@ -937,7 +939,7 @@ TEST_F(MySqlHostDataSourceTest, multipleClientClasses6) {
 /// @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();
 }
 
@@ -950,7 +952,7 @@ TEST_F(MySqlHostDataSourceTest, multipleClientClassesBoth) {
 /// @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();
 }
 
@@ -969,7 +971,7 @@ TEST_F(MySqlHostDataSourceTest, multipleSubnetsHWAddr) {
 /// 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);
 }
 
@@ -990,7 +992,7 @@ TEST_F(MySqlHostDataSourceTest, multipleSubnetsClientId) {
 /// 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);
 }
 
@@ -1009,7 +1011,7 @@ TEST_F(MySqlHostDataSourceTest, subnetId6) {
 /// 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);
 }
 
@@ -1026,7 +1028,7 @@ TEST_F(MySqlHostDataSourceTest, addDuplicate6WithDUID) {
 /// 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();
 }
 
@@ -1043,7 +1045,7 @@ TEST_F(MySqlHostDataSourceTest, addDuplicate6WithHWAddr) {
 /// 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();
 }
 
@@ -1058,7 +1060,7 @@ TEST_F(MySqlHostDataSourceTest, addDuplicate4) {
 /// 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();
 }
 
@@ -1072,7 +1074,7 @@ TEST_F(MySqlHostDataSourceTest, optionsReservations4) {
 /// @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));
 }
@@ -1087,7 +1089,7 @@ TEST_F(MySqlHostDataSourceTest, optionsReservations6) {
 /// @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));
 }
@@ -1101,7 +1103,7 @@ TEST_F(MySqlHostDataSourceTest, optionsReservations46) {
 /// @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);
 }
 
@@ -1115,7 +1117,7 @@ TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations4) {
 /// @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));
 }
@@ -1130,7 +1132,7 @@ TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations6) {
 /// @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));
 }
@@ -1144,7 +1146,7 @@ TEST_F(MySqlHostDataSourceTest, formattedOptionsReservations46) {
 /// @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);
 }
 
@@ -1201,7 +1203,7 @@ TEST_F(MySqlHostDataSourceTest, testAddRollback) {
 /// 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_);
 
@@ -1256,7 +1258,7 @@ TEST_F(MySqlHostDataSourceTest, messageFields) {
 /// @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();
 }
 
@@ -1267,7 +1269,7 @@ TEST_F(MySqlHostDataSourceTest, deleteByAddr4) {
 
 /// @brief Check that delete(subnet-id, addr4) works.
 TEST_F(MySqlHostDataSourceTest, deleteByAddr4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteByAddr4();
 }
 
@@ -1278,7 +1280,7 @@ TEST_F(MySqlHostDataSourceTest, deleteById4) {
 
 /// @brief Check that delete(subnet4-id, identifier-type, identifier) works.
 TEST_F(MySqlHostDataSourceTest, deleteById4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteById4();
 }
 
@@ -1291,7 +1293,7 @@ TEST_F(MySqlHostDataSourceTest, deleteById4Options) {
 /// @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();
 }
 
@@ -1302,7 +1304,7 @@ TEST_F(MySqlHostDataSourceTest, deleteById6) {
 
 /// @brief Check that delete(subnet6-id, identifier-type, identifier) works.
 TEST_F(MySqlHostDataSourceTest, deleteById6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteById6();
 }
 
@@ -1315,7 +1317,7 @@ TEST_F(MySqlHostDataSourceTest, deleteById6Options) {
 /// @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();
 }
 
@@ -1328,7 +1330,7 @@ TEST_F(MySqlHostDataSourceTest, testMultipleHostsNoAddress4) {
 /// @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();
 }
 
@@ -1339,7 +1341,7 @@ TEST_F(MySqlHostDataSourceTest, testMultipleHosts6) {
 
 /// @brief Tests that multiple hosts can be specified within an IPv6 subnet.
 TEST_F(MySqlHostDataSourceTest, testMultipleHosts6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMultipleHosts6();
 }
 
index 9a167e6952830c20787249cea8a12dbf7a37ce1e..7f18d0a4cb4378272ef06e4af608614d4e4accef 100644 (file)
@@ -14,6 +14,7 @@
 #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>
@@ -30,6 +31,7 @@ using namespace isc::db;
 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;
 
@@ -205,7 +207,7 @@ TEST(MySqlOpenTest, OpenDatabase) {
 /// @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);
@@ -226,9 +228,6 @@ TEST(MySqlOpenTest, OpenDatabaseMultiThreading) {
     // Tidy up after the test
     destroyMySQLSchema(true);
     LeaseMgrFactory::destroy();
-
-    // Disable Multi-Threading.
-    MultiThreadingMgr::instance().setMode(false);
 }
 
 /// @brief Check the getType() method
@@ -308,7 +307,7 @@ TEST_F(MySqlLeaseMgrTest, basicLease4) {
 
 /// @brief Basic Lease4 Checks
 TEST_F(MySqlLeaseMgrTest, basicLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testBasicLease4();
 }
 
@@ -319,7 +318,7 @@ TEST_F(MySqlLeaseMgrTest, maxDate4) {
 
 /// @brief Check that Lease4 code safely handles invalid dates.
 TEST_F(MySqlLeaseMgrTest, maxDate4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMaxDate4();
 }
 
@@ -337,7 +336,7 @@ TEST_F(MySqlLeaseMgrTest, updateLease4) {
 
 /// @brief Lease4 update tests
 TEST_F(MySqlLeaseMgrTest, updateLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testUpdateLease4();
 }
 
@@ -352,7 +351,7 @@ TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease4) {
 ///
 /// 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();
 }
 
@@ -363,7 +362,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address
 TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddr1();
 }
 
@@ -374,7 +373,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address
 TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddr2();
 }
 
@@ -388,7 +387,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSize) {
 
 /// @brief Get lease4 by hardware address (2)
 TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSize();
 }
 
@@ -402,7 +401,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetId) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
 TEST_F(MySqlLeaseMgrTest, getLease4HwaddrSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSubnetId();
 }
 
@@ -416,7 +415,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSubnetIdSize) {
 
 /// @brief Get lease4 by hardware address and subnet ID (2)
 TEST_F(MySqlLeaseMgrTest, getLease4HWAddrSubnetIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSubnetIdSize();
 }
 
@@ -427,7 +426,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
 
 /// @brief This test was derived from memfile.
 TEST_F(MySqlLeaseMgrTest, getLease4ClientIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientId();
 }
 
@@ -441,7 +440,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientId2) {
 
 /// @brief Check GetLease4 methods - access by Client ID
 TEST_F(MySqlLeaseMgrTest, getLease4ClientId2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientId2();
 }
 
@@ -454,7 +453,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSize) {
 
 /// @brief Get Lease4 by client ID (2)
 TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientIdSize();
 }
 
@@ -468,7 +467,7 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetId) {
 
 /// @brief Check GetLease4 methods - access by Client ID & Subnet ID
 TEST_F(MySqlLeaseMgrTest, getLease4ClientIdSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientIdSubnetId();
 }
 
@@ -479,7 +478,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases4SubnetId) {
 
 /// @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();
 }
 
@@ -490,7 +489,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases4Hostname) {
 
 /// @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();
 }
 
@@ -501,7 +500,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases4) {
 
 /// @brief This test checks that all IPv4 leases are returned.
 TEST_F(MySqlLeaseMgrTest, getLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases4();
 }
 
@@ -512,7 +511,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases4Paged) {
 
 /// @brief Test that a range of IPv4 leases is returned with paging.
 TEST_F(MySqlLeaseMgrTest, getLeases4PagedMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases4Paged();
 }
 
@@ -523,7 +522,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6SubnetId) {
 
 /// @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();
 }
 
@@ -534,7 +533,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6Hostname) {
 
 /// @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();
 }
 
@@ -545,7 +544,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6) {
 
 /// @brief This test checks that all IPv6 leases are returned.
 TEST_F(MySqlLeaseMgrTest, getLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6();
 }
 
@@ -556,7 +555,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6Paged) {
 
 /// @brief Test that a range of IPv6 leases is returned with paging.
 TEST_F(MySqlLeaseMgrTest, getLeases6PagedMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6Paged();
 }
 
@@ -571,7 +570,7 @@ TEST_F(MySqlLeaseMgrTest, lease4NullClientId) {
 
 /// @brief Basic Lease4 Checks
 TEST_F(MySqlLeaseMgrTest, lease4NullClientIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease4NullClientId();
 }
 
@@ -585,7 +584,7 @@ TEST_F(MySqlLeaseMgrTest, lease4InvalidHostname) {
 
 /// @brief Verify that too long hostname for Lease4 is not accepted.
 TEST_F(MySqlLeaseMgrTest, lease4InvalidHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease4InvalidHostname();
 }
 
@@ -602,7 +601,7 @@ TEST_F(MySqlLeaseMgrTest, getExpiredLeases4) {
 
 /// @brief Check that the expired DHCPv4 leases can be retrieved.
 TEST_F(MySqlLeaseMgrTest, getExpiredLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetExpiredLeases4();
 }
 
@@ -619,7 +618,7 @@ TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases4) {
 
 /// @brief Check that expired reclaimed DHCPv4 leases are removed.
 TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteExpiredReclaimedLeases4();
 }
 
@@ -636,7 +635,7 @@ TEST_F(MySqlLeaseMgrTest, testAddGetDelete6) {
 /// @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();
 }
 
@@ -650,7 +649,7 @@ TEST_F(MySqlLeaseMgrTest, basicLease6) {
 
 /// @brief Basic Lease6 Checks
 TEST_F(MySqlLeaseMgrTest, basicLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testBasicLease6();
 }
 
@@ -661,7 +660,7 @@ TEST_F(MySqlLeaseMgrTest, maxDate6) {
 
 /// @brief Check that Lease6 code safely handles invalid dates.
 TEST_F(MySqlLeaseMgrTest, maxDate6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMaxDate6();
 }
 
@@ -680,7 +679,7 @@ TEST_F(MySqlLeaseMgrTest, lease6InvalidHostname) {
 
 /// @brief Verify that too long hostname for Lease6 is not accepted.
 TEST_F(MySqlLeaseMgrTest, lease6InvalidHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6InvalidHostname();
 }
 
@@ -694,7 +693,7 @@ TEST_F(MySqlLeaseMgrTest, leases6LargeIaidCheck) {
 
 /// @brief Verify that large IAID values work correctly.
 TEST_F(MySqlLeaseMgrTest, leases6LargeIaidCheckMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6LargeIaidCheck();
 }
 
@@ -708,7 +707,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6DuidIaid) {
 
 /// @brief Check GetLease6 methods - access by DUID/IAID
 TEST_F(MySqlLeaseMgrTest, getLeases6DuidIaidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6DuidIaid();
 }
 
@@ -719,7 +718,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6DuidSize) {
 
 /// @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();
 }
 
@@ -735,7 +734,7 @@ TEST_F(MySqlLeaseMgrTest, lease6LeaseTypeCheck) {
 
 /// @brief Check that getLease6 methods discriminate by lease type.
 TEST_F(MySqlLeaseMgrTest, lease6LeaseTypeCheckMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6LeaseTypeCheck();
 }
 
@@ -749,7 +748,7 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
 
 /// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
 TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease6DuidIaidSubnetId();
 }
 
@@ -760,7 +759,7 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
 
 /// @brief Test checks that getLease6() works with different DUID sizes
 TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSubnetIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease6DuidIaidSubnetIdSize();
 }
 
@@ -774,7 +773,7 @@ TEST_F(MySqlLeaseMgrTest, getLeases6Duid) {
 
 /// @brief check leases could be retrieved by DUID
 TEST_F(MySqlLeaseMgrTest, getLeases6DuidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6Duid();
 }
 
@@ -787,7 +786,7 @@ TEST_F(MySqlLeaseMgrTest, updateLease6) {
 
 /// @brief Lease6 update tests
 TEST_F(MySqlLeaseMgrTest, updateLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testUpdateLease6();
 }
 
@@ -802,7 +801,7 @@ TEST_F(MySqlLeaseMgrTest, concurrentUpdateLease6) {
 ///
 /// 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();
 }
 
@@ -817,7 +816,7 @@ TEST_F(MySqlLeaseMgrTest, testRecreateLease4) {
 
 /// @brief DHCPv4 Lease recreation tests
 TEST_F(MySqlLeaseMgrTest, testRecreateLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecreateLease4();
 }
 
@@ -832,7 +831,7 @@ TEST_F(MySqlLeaseMgrTest, testRecreateLease6) {
 
 /// @brief DHCPv6 Lease recreation tests
 TEST_F(MySqlLeaseMgrTest, testRecreateLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecreateLease6();
 }
 
@@ -843,7 +842,7 @@ TEST_F(MySqlLeaseMgrTest, nullDuid) {
 
 /// @brief Checks that null DUID is not allowed.
 TEST_F(MySqlLeaseMgrTest, nullDuidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testNullDuid();
 }
 
@@ -854,7 +853,7 @@ TEST_F(MySqlLeaseMgrTest, testLease6Mac) {
 
 /// @brief Tests whether MySQL can store and retrieve hardware addresses
 TEST_F(MySqlLeaseMgrTest, testLease6MacMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6MAC();
 }
 
@@ -865,7 +864,7 @@ TEST_F(MySqlLeaseMgrTest, testLease6HWTypeAndSource) {
 
 /// @brief Tests whether MySQL can store and retrieve hardware addresses
 TEST_F(MySqlLeaseMgrTest, testLease6HWTypeAndSourceMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6HWTypeAndSource();
 }
 
@@ -882,7 +881,7 @@ TEST_F(MySqlLeaseMgrTest, getExpiredLeases6) {
 
 /// @brief Check that the expired DHCPv6 leases can be retrieved.
 TEST_F(MySqlLeaseMgrTest, getExpiredLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetExpiredLeases6();
 }
 
@@ -899,7 +898,7 @@ TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases6) {
 
 /// @brief Check that expired reclaimed DHCPv6 leases are removed.
 TEST_F(MySqlLeaseMgrTest, deleteExpiredReclaimedLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteExpiredReclaimedLeases6();
 }
 
@@ -910,7 +909,7 @@ TEST_F(MySqlLeaseMgrTest, recountLeaseStats4) {
 
 /// @brief Verifies that IPv4 lease statistics can be recalculated.
 TEST_F(MySqlLeaseMgrTest, recountLeaseStats4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecountLeaseStats4();
 }
 
@@ -921,7 +920,7 @@ TEST_F(MySqlLeaseMgrTest, recountLeaseStats6) {
 
 /// @brief Verifies that IPv6 lease statistics can be recalculated.
 TEST_F(MySqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecountLeaseStats6();
 }
 
@@ -932,7 +931,7 @@ TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4) {
 
 /// @brief Tests that leases from specific subnet can be removed.
 TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testWipeLeases4();
 }
 
@@ -943,7 +942,7 @@ TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6) {
 
 /// @brief Tests that leases from specific subnet can be removed.
 TEST_F(MySqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testWipeLeases6();
 }
 
@@ -971,25 +970,25 @@ public:
 
 /// @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();
 }
 
@@ -1000,7 +999,7 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQuery4) {
 
 /// @brief Tests v4 lease stats query variants.
 TEST_F(MySqlLeaseMgrTest, leaseStatsQuery4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQuery4();
 }
 
@@ -1011,7 +1010,7 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6) {
 
 /// @brief Tests v6 lease stats query variants.
 TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQuery6();
 }
 
@@ -1022,7 +1021,7 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution4) {
 
 /// @brief Tests v4 lease stats to be attributed to the wrong subnet.
 TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQueryAttribution4();
 }
 
@@ -1033,7 +1032,7 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution6) {
 
 /// @brief Tests v6 lease stats to be attributed to the wrong subnet.
 TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQueryAttribution6();
 }
 
index 028c6aa786e10900e8f42a6d8a664fb45c943512..2065f75fd6ebedd86ecc093fd8f0e14eca0a7a83 100644 (file)
@@ -18,6 +18,7 @@
 #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>
 
@@ -34,6 +35,7 @@ using namespace isc::db::test;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::data;
+using namespace isc::test;
 using namespace isc::util;
 using namespace std;
 
@@ -240,7 +242,7 @@ TEST(PgSqlHostDataSource, OpenDatabase) {
 /// 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();
@@ -359,7 +361,7 @@ TEST(PgSqlHostDataSource, NoCallbackOnOpenFail) {
 /// 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();
@@ -383,7 +385,7 @@ TEST_F(PgSqlHostDataSourceTest, testReadOnlyDatabase) {
 
 /// @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);
 }
 
@@ -396,7 +398,7 @@ TEST_F(PgSqlHostDataSourceTest, basic4HWAddr) {
 /// @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);
 }
 
@@ -409,7 +411,7 @@ TEST_F(PgSqlHostDataSourceTest, globalSubnetId4) {
 /// @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();
 }
 
@@ -422,7 +424,7 @@ TEST_F(PgSqlHostDataSourceTest, globalSubnetId6) {
 /// @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();
 }
 
@@ -435,7 +437,7 @@ TEST_F(PgSqlHostDataSourceTest, maxSubnetId4) {
 /// @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();
 }
 
@@ -448,7 +450,7 @@ TEST_F(PgSqlHostDataSourceTest, maxSubnetId6) {
 /// @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();
 }
 
@@ -459,7 +461,7 @@ TEST_F(PgSqlHostDataSourceTest, getAll4BySubnet) {
 
 /// @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();
 }
 
@@ -470,7 +472,7 @@ TEST_F(PgSqlHostDataSourceTest, getAll6BySubnet) {
 
 /// @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();
 }
 
@@ -481,7 +483,7 @@ TEST_F(PgSqlHostDataSourceTest, getAllbyHostname) {
 
 /// @brief Verifies that host reservations with the same hostname can be retrieved
 TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetAllbyHostname();
 }
 
@@ -494,7 +496,7 @@ TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet4) {
 /// @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();
 }
 
@@ -507,7 +509,7 @@ TEST_F(PgSqlHostDataSourceTest, getAllbyHostnameSubnet6) {
 /// @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();
 }
 
@@ -520,7 +522,7 @@ TEST_F(PgSqlHostDataSourceTest, getPage4) {
 /// @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();
 }
 
@@ -533,7 +535,7 @@ TEST_F(PgSqlHostDataSourceTest, getPage6) {
 /// @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();
 }
 
@@ -546,7 +548,7 @@ TEST_F(PgSqlHostDataSourceTest, getPageLimit4) {
 /// @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);
 }
 
@@ -559,7 +561,7 @@ TEST_F(PgSqlHostDataSourceTest, getPageLimit6) {
 /// @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);
 }
 
@@ -572,7 +574,7 @@ TEST_F(PgSqlHostDataSourceTest, getPage4Subnets) {
 /// @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();
 }
 
@@ -585,7 +587,7 @@ TEST_F(PgSqlHostDataSourceTest, getPage6Subnets) {
 /// @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();
 }
 
@@ -598,7 +600,7 @@ TEST_F(PgSqlHostDataSourceTest, basic4ClientId) {
 /// @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);
 }
 
@@ -611,7 +613,7 @@ TEST_F(PgSqlHostDataSourceTest, getByIPv4HWaddr) {
 /// @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);
 }
 
@@ -624,7 +626,7 @@ TEST_F(PgSqlHostDataSourceTest, getByIPv4ClientId) {
 /// @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);
 }
 
@@ -637,7 +639,7 @@ TEST_F(PgSqlHostDataSourceTest, get4ByHWaddr) {
 /// @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);
 }
 
@@ -650,7 +652,7 @@ TEST_F(PgSqlHostDataSourceTest, get4ByDUID) {
 /// @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);
 }
 
@@ -663,7 +665,7 @@ TEST_F(PgSqlHostDataSourceTest, get4ByCircuitId) {
 /// @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);
 }
 
@@ -676,7 +678,7 @@ TEST_F(PgSqlHostDataSourceTest, get4ByClientId) {
 /// @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);
 }
 
@@ -687,7 +689,7 @@ TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId1) {
 
 /// @brief Test verifies if hardware address and client identifier are not confused.
 TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId1MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testHWAddrNotClientId();
 }
 
@@ -698,7 +700,7 @@ TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId2) {
 
 /// @brief Test verifies if hardware address and client identifier are not confused.
 TEST_F(PgSqlHostDataSourceTest, hwaddrNotClientId2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testClientIdNotHWAddr();
 }
 
@@ -709,7 +711,7 @@ TEST_F(PgSqlHostDataSourceTest, hostnameFQDN) {
 
 /// @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);
 }
 
@@ -722,7 +724,7 @@ TEST_F(PgSqlHostDataSourceTest, hostnameFQDN100) {
 /// @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);
 }
 
@@ -735,7 +737,7 @@ TEST_F(PgSqlHostDataSourceTest, noHostname) {
 /// @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);
 }
 
@@ -747,7 +749,7 @@ TEST_F(PgSqlHostDataSourceTest, usercontext) {
 
 /// @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));
 }
@@ -764,7 +766,7 @@ TEST_F(PgSqlHostDataSourceTest, DISABLED_hwaddrOrClientId1) {
 
 /// @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.
     ///
@@ -785,7 +787,7 @@ TEST_F(PgSqlHostDataSourceTest, DISABLED_hwaddrOrClientId2) {
 
 /// @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.
     ///
@@ -803,7 +805,7 @@ TEST_F(PgSqlHostDataSourceTest, get6AddrWithDuid) {
 /// @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);
 }
 
@@ -816,7 +818,7 @@ TEST_F(PgSqlHostDataSourceTest, get6AddrWithHWAddr) {
 /// @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);
 }
 
@@ -829,7 +831,7 @@ TEST_F(PgSqlHostDataSourceTest, get6PrefixWithDuid) {
 /// @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);
 }
 
@@ -842,7 +844,7 @@ TEST_F(PgSqlHostDataSourceTest, get6PrefixWithHWaddr) {
 /// @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);
 }
 
@@ -855,7 +857,7 @@ TEST_F(PgSqlHostDataSourceTest, get6SubnetPrefix) {
 /// @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();
 }
 
@@ -868,7 +870,7 @@ TEST_F(PgSqlHostDataSourceTest, get6ByHWaddr) {
 /// @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();
 }
 
@@ -881,7 +883,7 @@ TEST_F(PgSqlHostDataSourceTest, get6ByClientId) {
 /// @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();
 }
 
@@ -894,7 +896,7 @@ TEST_F(PgSqlHostDataSourceTest, addr6AndPrefix) {
 /// @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();
 }
 
@@ -907,7 +909,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleReservations) {
 /// @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();
 }
 
@@ -920,7 +922,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleReservationsDifferentOrder) {
 /// @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();
 }
 
@@ -933,7 +935,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleClientClasses4) {
 /// @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();
 }
 
@@ -946,7 +948,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleClientClasses6) {
 /// @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();
 }
 
@@ -959,7 +961,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleClientClassesBoth) {
 /// @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();
 }
 
@@ -978,7 +980,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleSubnetsHWAddr) {
 /// 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);
 }
 
@@ -999,7 +1001,7 @@ TEST_F(PgSqlHostDataSourceTest, multipleSubnetsClientId) {
 /// 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);
 }
 
@@ -1018,7 +1020,7 @@ TEST_F(PgSqlHostDataSourceTest, subnetId6) {
 /// 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);
 }
 
@@ -1035,7 +1037,7 @@ TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithDUID) {
 /// 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();
 }
 
@@ -1052,7 +1054,7 @@ TEST_F(PgSqlHostDataSourceTest, addDuplicate6WithHWAddr) {
 /// 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();
 }
 
@@ -1067,7 +1069,7 @@ TEST_F(PgSqlHostDataSourceTest, addDuplicate4) {
 /// 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();
 }
 
@@ -1081,7 +1083,7 @@ TEST_F(PgSqlHostDataSourceTest, optionsReservations4) {
 /// @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));
 }
@@ -1096,7 +1098,7 @@ TEST_F(PgSqlHostDataSourceTest, optionsReservations6) {
 /// @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));
 }
@@ -1110,7 +1112,7 @@ TEST_F(PgSqlHostDataSourceTest, optionsReservations46) {
 /// @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);
 }
 
@@ -1124,7 +1126,7 @@ TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations4) {
 /// @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));
 }
@@ -1139,7 +1141,7 @@ TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations6) {
 /// @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));
 }
@@ -1153,7 +1155,7 @@ TEST_F(PgSqlHostDataSourceTest, formattedOptionsReservations46) {
 /// @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);
 }
 
@@ -1210,7 +1212,7 @@ TEST_F(PgSqlHostDataSourceTest, testAddRollback) {
 /// 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_);
 
@@ -1265,7 +1267,7 @@ TEST_F(PgSqlHostDataSourceTest, messageFields) {
 /// @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();
 }
 
@@ -1276,7 +1278,7 @@ TEST_F(PgSqlHostDataSourceTest, deleteByAddr4) {
 
 /// @brief Check that delete(subnet-id, addr4) works.
 TEST_F(PgSqlHostDataSourceTest, deleteByAddr4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteByAddr4();
 }
 
@@ -1287,7 +1289,7 @@ TEST_F(PgSqlHostDataSourceTest, deleteById4) {
 
 /// @brief Check that delete(subnet4-id, identifier-type, identifier) works.
 TEST_F(PgSqlHostDataSourceTest, deleteById4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteById4();
 }
 
@@ -1300,7 +1302,7 @@ TEST_F(PgSqlHostDataSourceTest, deleteById4Options) {
 /// @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();
 }
 
@@ -1311,7 +1313,7 @@ TEST_F(PgSqlHostDataSourceTest, deleteById6) {
 
 /// @brief Check that delete(subnet6-id, identifier-type, identifier) works.
 TEST_F(PgSqlHostDataSourceTest, deleteById6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteById6();
 }
 
@@ -1324,7 +1326,7 @@ TEST_F(PgSqlHostDataSourceTest, deleteById6Options) {
 /// @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();
 }
 
@@ -1337,7 +1339,7 @@ TEST_F(PgSqlHostDataSourceTest, testMultipleHostsNoAddress4) {
 /// @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();
 }
 
@@ -1348,7 +1350,7 @@ TEST_F(PgSqlHostDataSourceTest, testMultipleHosts6) {
 
 /// @brief Tests that multiple hosts can be specified within an IPv6 subnet.
 TEST_F(PgSqlHostDataSourceTest, testMultipleHosts6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMultipleHosts6();
 }
 
index 70776ec6440b6ec3d44f8c6add33d26a264b09de..c12dd7eb8d6ac4a8a762ef217d98b5f42cb9084d 100644 (file)
@@ -14,6 +14,7 @@
 #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>
@@ -30,6 +31,7 @@ using namespace isc::db;
 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;
 
@@ -202,7 +204,7 @@ TEST(PgSqlOpenTest, OpenDatabase) {
 /// @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();
@@ -223,9 +225,6 @@ TEST(PgSqlOpenTest, OpenDatabaseMultiThreading) {
     // Tidy up after the test
     destroyPgSQLSchema();
     LeaseMgrFactory::destroy();
-
-    // Disable Multi-Threading.
-    MultiThreadingMgr::instance().setMode(false);
 }
 
 /// @brief Check the getType() method
@@ -264,7 +263,7 @@ TEST_F(PgSqlLeaseMgrTest, basicLease4) {
 
 /// @brief Basic Lease4 Checks
 TEST_F(PgSqlLeaseMgrTest, basicLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testBasicLease4();
 }
 
@@ -275,7 +274,7 @@ TEST_F(PgSqlLeaseMgrTest, maxDate4) {
 
 /// @brief Check that Lease4 code safely handles invalid dates.
 TEST_F(PgSqlLeaseMgrTest, maxDate4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMaxDate4();
 }
 
@@ -293,7 +292,7 @@ TEST_F(PgSqlLeaseMgrTest, updateLease4) {
 
 /// @brief Lease4 update tests
 TEST_F(PgSqlLeaseMgrTest, updateLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testUpdateLease4();
 }
 
@@ -308,7 +307,7 @@ TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease4) {
 ///
 /// 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();
 }
 
@@ -319,7 +318,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr1) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address
 TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr1MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddr1();
 }
 
@@ -330,7 +329,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr2) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address
 TEST_F(PgSqlLeaseMgrTest, getLease4HWAddr2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddr2();
 }
 
@@ -344,7 +343,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSize) {
 
 /// @brief Get lease4 by hardware address (2)
 TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSize();
 }
 
@@ -358,7 +357,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4HwaddrSubnetId) {
 
 /// @brief Check GetLease4 methods - access by Hardware Address & Subnet ID
 TEST_F(PgSqlLeaseMgrTest, getLease4HwaddrSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSubnetId();
 }
 
@@ -372,7 +371,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSubnetIdSize) {
 
 /// @brief Get lease4 by hardware address and subnet ID (2)
 TEST_F(PgSqlLeaseMgrTest, getLease4HWAddrSubnetIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4HWAddrSubnetIdSize();
 }
 
@@ -383,7 +382,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4ClientId) {
 
 /// @brief This test was derived from memfile.
 TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientId();
 }
 
@@ -397,7 +396,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4ClientId2) {
 
 /// @brief Check GetLease4 methods - access by Client ID
 TEST_F(PgSqlLeaseMgrTest, getLease4ClientId2MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientId2();
 }
 
@@ -410,7 +409,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSize) {
 
 /// @brief Get Lease4 by client ID (2)
 TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientIdSize();
 }
 
@@ -424,7 +423,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSubnetId) {
 
 /// @brief Check GetLease4 methods - access by Client ID & Subnet ID
 TEST_F(PgSqlLeaseMgrTest, getLease4ClientIdSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease4ClientIdSubnetId();
 }
 
@@ -435,7 +434,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4SubnetId) {
 
 /// @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();
 }
 
@@ -446,7 +445,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4Hostname) {
 
 /// @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();
 }
 
@@ -457,7 +456,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4) {
 
 /// @brief This test checks that all IPv4 leases are returned.
 TEST_F(PgSqlLeaseMgrTest, getLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases4();
 }
 
@@ -468,7 +467,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4Paged) {
 
 /// @brief Test that a range of IPv4 leases is returned with paging.
 TEST_F(PgSqlLeaseMgrTest, getLeases4PagedMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases4Paged();
 }
 
@@ -479,7 +478,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetId) {
 
 /// @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();
 }
 
@@ -490,7 +489,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6Hostname) {
 
 /// @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();
 }
 
@@ -501,7 +500,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6) {
 
 /// @brief This test checks that all IPv6 leases are returned.
 TEST_F(PgSqlLeaseMgrTest, getLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6();
 }
 
@@ -512,7 +511,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6Paged) {
 
 /// @brief Test that a range of IPv6 leases is returned with paging.
 TEST_F(PgSqlLeaseMgrTest, getLeases6PagedMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6Paged();
 }
 
@@ -527,7 +526,7 @@ TEST_F(PgSqlLeaseMgrTest, lease4NullClientId) {
 
 /// @brief Basic Lease4 Checks
 TEST_F(PgSqlLeaseMgrTest, lease4NullClientIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease4NullClientId();
 }
 
@@ -541,7 +540,7 @@ TEST_F(PgSqlLeaseMgrTest, lease4InvalidHostname) {
 
 /// @brief Verify that too long hostname for Lease4 is not accepted.
 TEST_F(PgSqlLeaseMgrTest, lease4InvalidHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease4InvalidHostname();
 }
 
@@ -558,7 +557,7 @@ TEST_F(PgSqlLeaseMgrTest, getExpiredLeases4) {
 
 /// @brief Check that the expired DHCPv4 leases can be retrieved.
 TEST_F(PgSqlLeaseMgrTest, getExpiredLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetExpiredLeases4();
 }
 
@@ -575,7 +574,7 @@ TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases4) {
 
 /// @brief Check that expired reclaimed DHCPv4 leases are removed.
 TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteExpiredReclaimedLeases4();
 }
 
@@ -592,7 +591,7 @@ TEST_F(PgSqlLeaseMgrTest, testAddGetDelete6) {
 /// @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();
 }
 
@@ -606,7 +605,7 @@ TEST_F(PgSqlLeaseMgrTest, basicLease6) {
 
 /// @brief Basic Lease6 Checks
 TEST_F(PgSqlLeaseMgrTest, basicLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testBasicLease6();
 }
 
@@ -617,7 +616,7 @@ TEST_F(PgSqlLeaseMgrTest, maxDate6) {
 
 /// @brief Check that Lease6 code safely handles invalid dates.
 TEST_F(PgSqlLeaseMgrTest, maxDate6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testMaxDate6();
 }
 
@@ -636,7 +635,7 @@ TEST_F(PgSqlLeaseMgrTest, lease6InvalidHostname) {
 
 /// @brief Verify that too long hostname for Lease6 is not accepted.
 TEST_F(PgSqlLeaseMgrTest, lease6InvalidHostnameMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6InvalidHostname();
 }
 
@@ -650,7 +649,7 @@ TEST_F(PgSqlLeaseMgrTest, leases6LargeIaidCheck) {
 
 /// @brief Verify that large IAID values work correctly.
 TEST_F(PgSqlLeaseMgrTest, leases6LargeIaidCheckMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6LargeIaidCheck();
 }
 
@@ -664,7 +663,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6DuidIaid) {
 
 /// @brief Check GetLease6 methods - access by DUID/IAID
 TEST_F(PgSqlLeaseMgrTest, getLeases6DuidIaidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6DuidIaid();
 }
 
@@ -675,7 +674,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6DuidSize) {
 
 /// @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();
 }
 
@@ -691,7 +690,7 @@ TEST_F(PgSqlLeaseMgrTest, lease6LeaseTypeCheck) {
 
 /// @brief Check that getLease6 methods discriminate by lease type.
 TEST_F(PgSqlLeaseMgrTest, lease6LeaseTypeCheckMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6LeaseTypeCheck();
 }
 
@@ -705,7 +704,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetId) {
 
 /// @brief Check GetLease6 methods - access by DUID/IAID/SubnetID
 TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetIdMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease6DuidIaidSubnetId();
 }
 
@@ -716,7 +715,7 @@ TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetIdSize) {
 
 /// @brief Test checks that getLease6() works with different DUID sizes
 TEST_F(PgSqlLeaseMgrTest, getLease6DuidIaidSubnetIdSizeMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLease6DuidIaidSubnetIdSize();
 }
 
@@ -730,7 +729,7 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6Duid) {
 
 /// @brief check leases could be retrieved by DUID
 TEST_F(PgSqlLeaseMgrTest, getLeases6DuidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetLeases6Duid();
 }
 
@@ -743,7 +742,7 @@ TEST_F(PgSqlLeaseMgrTest, updateLease6) {
 
 /// @brief Lease6 update tests
 TEST_F(PgSqlLeaseMgrTest, updateLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testUpdateLease6();
 }
 
@@ -758,7 +757,7 @@ TEST_F(PgSqlLeaseMgrTest, concurrentUpdateLease6) {
 ///
 /// 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();
 }
 
@@ -773,7 +772,7 @@ TEST_F(PgSqlLeaseMgrTest, testRecreateLease4) {
 
 /// @brief DHCPv4 Lease recreation tests
 TEST_F(PgSqlLeaseMgrTest, testRecreateLease4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecreateLease4();
 }
 
@@ -788,7 +787,7 @@ TEST_F(PgSqlLeaseMgrTest, testRecreateLease6) {
 
 /// @brief DHCPv6 Lease recreation tests
 TEST_F(PgSqlLeaseMgrTest, testRecreateLease6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecreateLease6();
 }
 
@@ -799,7 +798,7 @@ TEST_F(PgSqlLeaseMgrTest, nullDuid) {
 
 /// @brief Checks that null DUID is not allowed.
 TEST_F(PgSqlLeaseMgrTest, nullDuidMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testNullDuid();
 }
 
@@ -810,7 +809,7 @@ TEST_F(PgSqlLeaseMgrTest, testLease6Mac) {
 
 /// @brief Tests whether PostgreSQL can store and retrieve hardware addresses
 TEST_F(PgSqlLeaseMgrTest, testLease6MacMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6MAC();
 }
 
@@ -821,7 +820,7 @@ TEST_F(PgSqlLeaseMgrTest, testLease6HWTypeAndSource) {
 
 /// @brief Tests whether PostgreSQL can store and retrieve hardware addresses
 TEST_F(PgSqlLeaseMgrTest, testLease6HWTypeAndSourceMultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLease6HWTypeAndSource();
 }
 
@@ -838,7 +837,7 @@ TEST_F(PgSqlLeaseMgrTest, getExpiredLeases6) {
 
 /// @brief Check that the expired DHCPv6 leases can be retrieved.
 TEST_F(PgSqlLeaseMgrTest, getExpiredLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testGetExpiredLeases6();
 }
 
@@ -855,7 +854,7 @@ TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases6) {
 
 /// @brief Check that expired reclaimed DHCPv6 leases are removed.
 TEST_F(PgSqlLeaseMgrTest, deleteExpiredReclaimedLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testDeleteExpiredReclaimedLeases6();
 }
 
@@ -866,7 +865,7 @@ TEST_F(PgSqlLeaseMgrTest, recountLeaseStats4) {
 
 /// @brief Verifies that IPv4 lease statistics can be recalculated.
 TEST_F(PgSqlLeaseMgrTest, recountLeaseStats4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecountLeaseStats4();
 }
 
@@ -877,7 +876,7 @@ TEST_F(PgSqlLeaseMgrTest, recountLeaseStats6) {
 
 /// @brief Verifies that IPv6 lease statistics can be recalculated.
 TEST_F(PgSqlLeaseMgrTest, recountLeaseStats6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testRecountLeaseStats6();
 }
 
@@ -888,7 +887,7 @@ TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases4) {
 
 /// @brief Tests that leases from specific subnet can be removed.
 TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testWipeLeases4();
 }
 
@@ -899,7 +898,7 @@ TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases6) {
 
 /// @brief Tests that leases from specific subnet can be removed.
 TEST_F(PgSqlLeaseMgrTest, DISABLED_wipeLeases6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testWipeLeases6();
 }
 
@@ -927,25 +926,25 @@ public:
 
 /// @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();
 }
 
@@ -956,7 +955,7 @@ TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery4) {
 
 /// @brief Tests v4 lease stats query variants.
 TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQuery4();
 }
 
@@ -967,7 +966,7 @@ TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery6) {
 
 /// @brief Tests v6 lease stats query variants.
 TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQuery6();
 }
 
@@ -978,7 +977,7 @@ TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution4) {
 
 /// @brief Tests v4 lease stats to be attributed to the wrong subnet.
 TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution4MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQueryAttribution4();
 }
 
@@ -989,7 +988,7 @@ TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution6) {
 
 /// @brief Tests v6 lease stats to be attributed to the wrong subnet.
 TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryAttribution6MultiThreading) {
-    MultiThreadingMgr::instance().setMode(true);
+    MultiThreadingTest mt(true);
     testLeaseStatsQueryAttribution6();
 }
 
index 9f0a50882f7e904268f600c8868ef816e6165799..1c1e0eaad01c710da9eda014c5da9ac6d43e9a68 100644 (file)
@@ -13,7 +13,7 @@
 #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>
@@ -22,7 +22,7 @@
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::dhcp;
-using namespace isc::util;
+using namespace isc::test;
 
 namespace {
 
@@ -456,7 +456,7 @@ TEST(SharedNetwork4Test, getPreferredSubnet) {
 // 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.
@@ -534,7 +534,6 @@ TEST(SharedNetwork4Test, getPreferredSubnetMultiThreading) {
     // 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.
@@ -1201,7 +1200,7 @@ TEST(SharedNetwork6Test, getPreferredSubnet) {
 // 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.
@@ -1294,7 +1293,6 @@ TEST(SharedNetwork6Test, getPreferredSubnetMultiThreading) {
     // 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.
index 139f89e87e164405bb4dee3e2d364df15a43b23d..ef1922a1478e3a4e9c3d5a31e5c29ee8ea585792 100644 (file)
@@ -18,7 +18,7 @@
 #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>
@@ -32,7 +32,7 @@ using boost::scoped_ptr;
 using namespace isc;
 using namespace isc::dhcp;
 using namespace isc::asiolink;
-using namespace isc::util;
+using namespace isc::test;
 
 namespace {
 
@@ -709,7 +709,7 @@ TEST(Subnet4Test, lastAllocated) {
 
 // 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");
@@ -727,7 +727,6 @@ TEST(Subnet4Test, lastAllocatedMultiThreading) {
     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()
@@ -1756,7 +1755,7 @@ TEST(Subnet6Test, lastAllocated) {
 
 // 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");
@@ -1788,7 +1787,6 @@ TEST(Subnet6Test, lastAllocatedMultiThreading) {
 
     // 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.
index 1afd543328fc33f54603be13d24316378b06cc7d..756b9cfc575dcff8b13bf630c3fd335b7d661cf3 100644 (file)
@@ -15,6 +15,7 @@ libkea_testutils_la_SOURCES += threaded_test.cc threaded_test.h
 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
diff --git a/src/lib/testutils/multi_threading_utils.h b/src/lib/testutils/multi_threading_utils.h
new file mode 100644 (file)
index 0000000..e070f54
--- /dev/null
@@ -0,0 +1,38 @@
+// 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