]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1196] Checkpoint: added bug trigger tests
authorFrancis Dupont <fdupont@isc.org>
Tue, 19 May 2020 16:22:52 +0000 (18:22 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 19 Jun 2020 15:04:50 +0000 (17:04 +0200)
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

index 75ff6c083b0211c19d7188c66402d9c635315775..cc221636120c5da15ab9a7c3212fc184bbcf9c1f 100644 (file)
@@ -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
index 30272e35868d89efeb96fc631c1d1ac6636d06fe..c717a3e0737dca2f7ebf5dd819eec94e8cc97a7b 100644 (file)
@@ -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
index b6b0bd30ea959ab10f796910b3f478c90026c43e..0de0e80dbc631dfac037e8c459fd265cc3c18ca1 100644 (file)
@@ -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
index 2093c7d64d7b5b2fc670adc8e603415ab6ce4881..377bb4f0e4f030925eee361a99dcead9f6cce9e9 100644 (file)
@@ -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
index 8481a87737f3289dda93ac8ee34046ca518543d0..e703159c2d3e9548075cb667fd4500b8cf45409b 100644 (file)
@@ -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
index c4f449e8a440d50bb6ac7167d7fa95d900d2446f..39b0883e9633cbb43a8ced9675f00788f200ce2c 100644 (file)
@@ -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