From: Francis Dupont Date: Tue, 19 May 2020 16:22:52 +0000 (+0200) Subject: [#1196] Checkpoint: added bug trigger tests X-Git-Tag: Kea-1.7.9~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcc64131e74e2aef4c529ae2c4dea568cd53162c;p=thirdparty%2Fkea.git [#1196] Checkpoint: added bug trigger tests --- diff --git a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc index 75ff6c083b..cc22163612 100644 --- a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc @@ -858,4 +858,14 @@ TEST_F(CqlLeaseMgrTest, leaseStatsQuery6) { testLeaseStatsQuery6(); } +/// @brief Tests v4 lease stats to never go negative. +TEST_F(CqlLeaseMgrTest, leaseStatsQueryNegative4) { + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(CqlLeaseMgrTest, leaseStatsQueryNegative6) { + testLeaseStatsQueryNegative6(); +} + } // namespace diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 30272e3586..c717a3e073 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -3355,7 +3355,7 @@ GenericLeaseMgrTest::checkQueryAgainstRowSet(const LeaseStatsQueryPtr& query, << " count: " << row.state_count_; } else { if (row.state_count_ != (*found_row).state_count_) { - ADD_FAILURE() << "row count wrong for " + ADD_FAILURE() << "row count wrong for" << " id: " << row.subnet_id_ << " type: " << row.lease_type_ << " state: " << row.lease_state_ @@ -3629,6 +3629,93 @@ GenericLeaseMgrTest::testLeaseStatsQuery6() { } } +void +GenericLeaseMgrTest::testLeaseStatsQueryNegative4() { + // Create two subnets for the same range. + CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); + Subnet4Ptr subnet; + + subnet.reset(new Subnet4(IOAddress("192.0.1.0"), 24, 1, 2, 3, 1)); + cfg->add(subnet); + + subnet.reset(new Subnet4(IOAddress("192.0.1.1"), 24, 1, 2, 3, 2)); + cfg->add(subnet); + + ASSERT_NO_THROW(CfgMgr::instance().commit()); + + LeaseStatsQueryPtr query; + RowSet expected_rows; + + // Now let's insert two leases into subnet 1. + int subnet_id = 1; + makeLease4("192.0.1.1", subnet_id); + Lease4Ptr lease = makeLease4("192.0.1.2", subnet_id); + + // And one lease into subnet 2. + subnet_id = 2; + makeLease4("192.0.1.3", subnet_id); + + // Move a lease to the second subnet. + lease->subnet_id_ = subnet_id; + EXPECT_NO_THROW(lmptr_->updateLease4(lease)); + + // Add expected rows for Subnets. + expected_rows.insert(LeaseStatsRow(1, Lease::STATE_DEFAULT, 1)); + expected_rows.insert(LeaseStatsRow(2, Lease::STATE_DEFAULT, 2)); + + // Start the query + ASSERT_NO_THROW(query = lmptr_->startLeaseStatsQuery4()); + + // Verify contents + checkQueryAgainstRowSet(query, expected_rows); +} + +void +GenericLeaseMgrTest::testLeaseStatsQueryNegative6() { + // Create two subnets. + CfgSubnets6Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets6(); + Subnet6Ptr subnet; + + int subnet_id = 1; + subnet.reset(new Subnet6(IOAddress("2001:db8:1::"), 64, 1, 2, 3, 4, + subnet_id)); + cfg->add(subnet); + + ++subnet_id; + subnet.reset(new Subnet6(IOAddress("2001:db8:1::1"), 64, 1, 2, 3, 4, + subnet_id)); + cfg->add(subnet); + + ASSERT_NO_THROW(CfgMgr::instance().commit()); + + LeaseStatsQueryPtr query; + RowSet expected_rows; + + // Now let's insert two leases into subnet 1. + subnet_id = 1; + makeLease6(Lease::TYPE_NA, "2001:db81::1", 0, subnet_id); + Lease6Ptr lease = makeLease6(Lease::TYPE_NA, "2001:db81::2", 0, subnet_id); + + // And one lease into subnet 2. + subnet_id = 2; + makeLease6(Lease::TYPE_NA, "2001:db81::3", 0, subnet_id); + + // Move a lease to the second subnet. + lease->subnet_id_ = subnet_id; + EXPECT_NO_THROW(lmptr_->updateLease6(lease)); + + // Add expected rows for Subnets. + expected_rows.insert(LeaseStatsRow(1, Lease::TYPE_NA, + Lease::STATE_DEFAULT, 1)); + expected_rows.insert(LeaseStatsRow(2, Lease::TYPE_NA, + Lease::STATE_DEFAULT, 2)); + // Start the query + ASSERT_NO_THROW(query = lmptr_->startLeaseStatsQuery6()); + + // Verify contents + checkQueryAgainstRowSet(query, expected_rows); +} + } // namespace test } // namespace dhcp } // namespace isc diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h index b6b0bd30ea..0de0e80dbc 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h @@ -467,6 +467,24 @@ public: /// void testLeaseStatsQuery6(); + /// @brief Checks if v4 LeaseStatsQuery can get negative counters + /// + /// It creates two subnets with leases and move one from the first + /// to the second. If counters are not updated this can lead to + /// negative counters. + /// + void testLeaseStatsQueryNegative4(); + + /// @brief Checks if v6 LeaseStatsQuery can get negative counters + /// + /// It creates two subnets with leases and move one from the first + /// to the second. If counters are not updated this can lead to + /// negative counters. + /// + /// @note We can check the lease type change too but in the real + /// world this never happens. + void testLeaseStatsQueryNegative6(); + /// @brief Compares LeaseQueryStats content to expected set of rows /// /// @param qry - a started LeaseStatsQuery diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 2093c7d64d..377bb4f0e4 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -2258,4 +2258,16 @@ TEST_F(MemfileLeaseMgrTest, leaseStatsQuery6) { testLeaseStatsQuery6(); } +/// @brief Tests v4 lease stats to never go negative. +TEST_F(MemfileLeaseMgrTest, leaseStatsQueryNegative4) { + startBackend(V4); + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(MemfileLeaseMgrTest, leaseStatsQueryNegative6) { + startBackend(V6); + testLeaseStatsQueryNegative6(); +} + } // namespace diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 8481a87737..e703159c2d 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -1015,4 +1015,26 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQuery6MultiThreading) { testLeaseStatsQuery6(); } +/// @brief Tests v4 lease stats to never go negative. +TEST_F(MySqlLeaseMgrTest, leaseStatsQueryNegative4) { + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v4 lease stats to never go negative. +TEST_F(MySqlLeaseMgrTest, leaseStatsQueryNegative4MultiThreading) { + MultiThreadingMgr::instance().setMode(true); + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(MySqlLeaseMgrTest, leaseStatsQueryNegative6) { + testLeaseStatsQueryNegative6(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(MySqlLeaseMgrTest, leaseStatsQueryNegative6MultiThreading) { + MultiThreadingMgr::instance().setMode(true); + testLeaseStatsQueryNegative6(); +} + } // namespace diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index c4f449e8a4..39b0883e96 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -971,4 +971,26 @@ TEST_F(PgSqlLeaseMgrTest, leaseStatsQuery6MultiThreading) { testLeaseStatsQuery6(); } +/// @brief Tests v4 lease stats to never go negative. +TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryNegative4) { + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v4 lease stats to never go negative. +TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryNegative4MultiThreading) { + MultiThreadingMgr::instance().setMode(true); + testLeaseStatsQueryNegative4(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryNegative6) { + testLeaseStatsQueryNegative6(); +} + +/// @brief Tests v6 lease stats to never go negative. +TEST_F(PgSqlLeaseMgrTest, leaseStatsQueryNegative6MultiThreading) { + MultiThreadingMgr::instance().setMode(true); + testLeaseStatsQueryNegative6(); +} + } // namespace