Browse Source

Even more ZoneEntry tests

This time with multiple nameservers

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3636 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
73da73cac2
2 changed files with 65 additions and 2 deletions
  1. 6 1
      src/lib/nsas/tests/nsas_test.h
  2. 59 1
      src/lib/nsas/tests/zone_entry_unittest.cc

+ 6 - 1
src/lib/nsas/tests/nsas_test.h

@@ -225,6 +225,10 @@ using namespace std;
  * they can be answered.
  */
 class TestResolver : public isc::nsas::ResolverInterface {
+    private:
+        void checkIndex(size_t index) {
+            ASSERT_GT(requests.size(), index);
+        }
     public:
         typedef pair<QuestionPtr, CallbackPtr> Request;
         vector<Request> requests;
@@ -232,6 +236,7 @@ class TestResolver : public isc::nsas::ResolverInterface {
             requests.push_back(Request(q, c));
         }
         QuestionPtr operator[](size_t index) {
+            checkIndex(index);
             return (requests[index].first);
         }
         /*
@@ -240,7 +245,7 @@ class TestResolver : public isc::nsas::ResolverInterface {
          */
         void asksIPs(const Name& name, size_t index1, size_t index2) {
             size_t max = (index1 < index2) ? index2 : index1;
-            ASSERT_GT(requests.size(), max);
+            checkIndex(max);
             EXPECT_EQ(name, (*this)[index1]->getName());
             EXPECT_EQ(name, (*this)[index2]->getName());
             EXPECT_EQ(RRClass::IN(), (*this)[index1]->getClass());

+ 59 - 1
src/lib/nsas/tests/zone_entry_unittest.cc

@@ -106,6 +106,7 @@ TEST_F(ZoneEntryTest, ReferralConstructor) {
     // TODO Test with some additional data once NameserverEntry supports them?
 }
 
+// It should answer negatively right away if there are no nameservers
 TEST_F(ZoneEntryTest, CallbackNoNS) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
         rr_empty_, vector<const AbstractRRset*>(), nameservers_hash_,
@@ -117,6 +118,7 @@ TEST_F(ZoneEntryTest, CallbackNoNS) {
     EXPECT_EQ(1, callback_->unreachable_count_);
 }
 
+// Check it accepts the first callback with 0 TTL
 TEST_F(ZoneEntryTest, CallbackZeroTTL) {
     // Make it zero TTL, so it expires right away
     rr_single_.setTTL(RRTTL(0));
@@ -133,6 +135,7 @@ TEST_F(ZoneEntryTest, CallbackZeroTTL) {
     EXPECT_FALSE(zone->addCallback(callback_, ANY_OK, zone));
 }
 
+// Check it answers callbacks when we give it addresses
 TEST_F(ZoneEntryTest, CallbacksAnswered) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
         rr_single_, vector<const AbstractRRset*>(), nameservers_hash_,
@@ -162,7 +165,7 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
     // We are still in progress, not everything arrived
     EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
     resolver_->answer(1, ns_name_, RRType::AAAA(),
-        rdata::in::A("2001:db8::1"));
+        rdata::in::AAAA("2001:db8::1"));
     // This should answer the third callback
     ASSERT_EQ(3, callback_->successes_.size());
     EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[2]));
@@ -177,6 +180,7 @@ TEST_F(ZoneEntryTest, CallbacksAnswered) {
     EXPECT_EQ(0, callback_->unreachable_count_);
 }
 
+// Pretend the server can be reached only by IPv4
 TEST_F(ZoneEntryTest, CallbacksAOnly) {
     shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
         rr_single_, vector<const AbstractRRset*>(), nameservers_hash_,
@@ -220,4 +224,58 @@ TEST_F(ZoneEntryTest, CallbacksAOnly) {
     EXPECT_EQ(2, callback_->unreachable_count_);
 }
 
+// See it tries hard enough to get address and tries both nameservers
+TEST_F(ZoneEntryTest, CallbackTwoNS) {
+    shared_ptr<InheritedZoneEntry> zone(new InheritedZoneEntry(resolver_,
+        rrns_, vector<const AbstractRRset*>(), nameservers_hash_,
+        nameservers_lru_));
+    // It should be in NOT_ASKED state
+    EXPECT_EQ(Fetchable::NOT_ASKED, zone->getState());
+    // It should accept the callback
+    EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
+    EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
+    // It asks a question (we do not know which nameserver)
+    resolver_->asksIPs((*resolver_)[0]->getName(), 0, 1);
+    resolver_->requests[0].second->failure();
+    // Nothing should be answered or failed yet
+    EXPECT_EQ(0, callback_->unreachable_count_);
+    EXPECT_EQ(0, callback_->successes_.size());
+    // It should be still IN_PROGRESS and ask the second nameserver
+    // (at last now, if not before)
+    EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
+    resolver_->asksIPs((*resolver_)[2]->getName(), 2, 3);
+    // Fail the second one
+    resolver_->requests[2].second->failure();
+    // The callback should be failed now, as there is no chance of getting
+    // v4 address
+    EXPECT_EQ(1, callback_->unreachable_count_);
+    EXPECT_EQ(0, callback_->successes_.size());
+    // We should still be IN_PROGRESS, waiting for v6
+    EXPECT_EQ(Fetchable::IN_PROGRESS, zone->getState());
+    // And question for v6 or any should still wait while v4 should be failed
+    // right away
+    EXPECT_TRUE(zone->addCallback(callback_, V6_ONLY, zone));
+    EXPECT_EQ(1, callback_->unreachable_count_);
+    EXPECT_EQ(0, callback_->successes_.size());
+
+    EXPECT_TRUE(zone->addCallback(callback_, ANY_OK, zone));
+    EXPECT_EQ(1, callback_->unreachable_count_);
+    EXPECT_EQ(0, callback_->successes_.size());
+
+    EXPECT_TRUE(zone->addCallback(callback_, V4_ONLY, zone));
+    EXPECT_EQ(2, callback_->unreachable_count_);
+    EXPECT_EQ(0, callback_->successes_.size());
+    // Answer the IPv6 one
+    resolver_->answer(1, (*resolver_)[1]->getName(), RRType::AAAA(),
+        rdata::in::AAAA("2001:db8::1"));
+
+    // Ready, as we have at last some address
+    EXPECT_EQ(Fetchable::READY, zone->getState());
+    // The other callbacks should be answered now
+    EXPECT_EQ(2, callback_->unreachable_count_);
+    ASSERT_EQ(2, callback_->successes_.size());
+    EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[0]));
+    EXPECT_TRUE(IOAddress("2001:db8::1").equal(callback_->successes_[1]));
+}
+
 }   // namespace