]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5638] Added commenary to simpleAlloc tests.
authorMarcin Siodelski <marcin@isc.org>
Tue, 5 Jun 2018 07:52:19 +0000 (09:52 +0200)
committerMarcin Siodelski <marcin@isc.org>
Tue, 5 Jun 2018 07:52:19 +0000 (09:52 +0200)
As a result of review.

src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
src/lib/dhcpsrv/tests/alloc_engine6_unittest.cc

index f46ca30c05221e28ea2559d4cd540bf29a611d9e..72e7d70896910ee4836daf536adc02524acaad88 100644 (file)
@@ -47,7 +47,16 @@ TEST_F(AllocEngine4Test, constructor) {
     EXPECT_THROW(x->getAllocator(Lease::TYPE_PD), BadValue);
 }
 
-// This test checks if the simple IPv4 allocation can succeed
+// This test checks if two simple IPv4 allocations succeed and that the
+// statistics is properly updated. Prior to the second allocation it
+// resets the pointer to the last allocated address within the address
+// pool. This causes the engine to walk over the already allocated
+// address and then pick the first available address for the second
+// allocation. Because the allocation engine checks the callouts next
+// step status after each attempt to allocate an address, this test
+// also sets this status to non-default value prior to the second
+// allocation attempt, to make sure that this unexpected status will
+// not interfere with the allocation.
 TEST_F(AllocEngine4Test, simpleAlloc4) {
     boost::scoped_ptr<AllocEngine> engine;
     ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE,
@@ -81,6 +90,7 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
     // Assigned addresses should have incremented.
     EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID()));
 
+    // Second allocation starts here.
     uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
     HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
     AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"),
@@ -88,12 +98,18 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
                                      false);
     ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234));
 
+    // Set the next step to non-default value to verify that it doesn't
+    // affect the allocation.
     ctx2.callout_handle_ = HooksManager::createCalloutHandle();
     ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP);
 
+    // Set the last allocated to the beginning of the pool. The allocation
+    // engine should detect that the first address is already allocated and
+    // assign the first available one.
     pool_->resetLastAllocated();
 
     lease = engine->allocateLease4(ctx2);
+
     // The new lease has been allocated, so the old lease should not exist.
     EXPECT_FALSE(ctx2.old_lease_);
 
@@ -106,6 +122,9 @@ TEST_F(AllocEngine4Test, simpleAlloc4) {
 
     // Now check that the lease in LeaseMgr has the same parameters
     detailCompareLease(lease, from_mgr);
+
+    // Assigned addresses should have incremented.
+    EXPECT_TRUE(testStatistics("assigned-addresses", 2, subnet_->getID()));
 }
 
 // This test checks if the fake allocation (for DHCPDISCOVER) can succeed
index e4baabdfcedac5fbbfa115a1e843c8e35e7ee949..8394fd79beb654841b228831374f5ccb4ec58575 100644 (file)
@@ -67,8 +67,16 @@ TEST_F(AllocEngine6Test, constructor) {
     EXPECT_THROW(x->getAllocator(Lease::TYPE_V4), BadValue);
 }
 
-// This test checks if the simple allocation (REQUEST) can succeed
-// and the stats counter is properly bumped by 1
+// This test checks if two simple IPv6 allocations succeed and that the
+// statistics is properly updated. Prior to the second allocation it
+// resets the pointer to the last allocated address within the address
+// pool. This causes the engine to walk over the already allocated
+// address and then pick the first available address for the second
+// allocation. Because the allocation engine checks the callouts next
+// step status after each attempt to allocate an address, this test
+// also sets this status to non-default value prior to the second
+// allocation attempt, to make sure that this unexpected status will
+// not interfere with the allocation.
 TEST_F(AllocEngine6Test, simpleAlloc6) {
     // Assigned count should be zero.
     EXPECT_TRUE(testStatistics("assigned-nas", 0, subnet_->getID()));