[svn] commit: r3636 - in /branches/trac408/src/lib/nsas/tests: nsas_test.h zone_entry_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Nov 25 09:59:05 UTC 2010
Author: vorner
Date: Thu Nov 25 09:59:04 2010
New Revision: 3636
Log:
Even more ZoneEntry tests
This time with multiple nameservers
Modified:
branches/trac408/src/lib/nsas/tests/nsas_test.h
branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
Modified: branches/trac408/src/lib/nsas/tests/nsas_test.h
==============================================================================
--- branches/trac408/src/lib/nsas/tests/nsas_test.h (original)
+++ branches/trac408/src/lib/nsas/tests/nsas_test.h Thu Nov 25 09:59:04 2010
@@ -225,6 +225,10 @@
* 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 @@
requests.push_back(Request(q, c));
}
QuestionPtr operator[](size_t index) {
+ checkIndex(index);
return (requests[index].first);
}
/*
@@ -240,7 +245,7 @@
*/
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());
Modified: branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
==============================================================================
--- branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc (original)
+++ branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc Thu Nov 25 09:59:04 2010
@@ -106,6 +106,7 @@
// 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 @@
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 @@
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 @@
// 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 @@
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 @@
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
More information about the bind10-changes
mailing list