catchunks: add --no-version-discovery option
Refs: #5021
Change-Id: I37bb1f86c1a6d63ab28fbe116e75d1047c110217
diff --git a/tests/chunks/discover-version.t.cpp b/tests/chunks/discover-version.t.cpp
index eb94f1d..9c3a844 100644
--- a/tests/chunks/discover-version.t.cpp
+++ b/tests/chunks/discover-version.t.cpp
@@ -44,50 +44,63 @@
void
run(const Name& prefix)
{
- BOOST_REQUIRE(!prefix.empty());
-
discover = make_unique<DiscoverVersion>(face, prefix, opt);
discover->onDiscoverySuccess.connect([this] (const Name& versionedName) {
- BOOST_REQUIRE(!versionedName.empty() && versionedName[-1].isVersion());
- discoveredVersion = versionedName[-1].toVersion();
isDiscoveryFinished = true;
+ discoveredName = versionedName;
+ if (!versionedName.empty() && versionedName[-1].isVersion())
+ discoveredVersion = versionedName[-1].toVersion();
});
discover->onDiscoveryFailure.connect([this] (const std::string&) {
isDiscoveryFinished = true;
});
discover->run();
- advanceClocks(io, time::nanoseconds(1));
+ advanceClocks(io, 1_ns);
}
protected:
+ const Name name = "/ndn/chunks/test";
+ const uint64_t version = 1449227841747;
boost::asio::io_service io;
util::DummyClientFace face{io};
- Name name = "/ndn/chunks/test";
Options opt;
unique_ptr<DiscoverVersion> discover;
+ optional<Name> discoveredName;
optional<uint64_t> discoveredVersion;
bool isDiscoveryFinished = false;
- uint64_t version = 1449227841747;
};
BOOST_AUTO_TEST_SUITE(Chunks)
BOOST_FIXTURE_TEST_SUITE(TestDiscoverVersion, DiscoverVersionFixture)
-BOOST_AUTO_TEST_CASE(VersionNumberIsProvided)
+BOOST_AUTO_TEST_CASE(Disabled)
{
- run(Name(name).appendVersion(version));
+ opt.disableVersionDiscovery = true;
+ run(name);
- // no version discovery interest is expressed
+ // no version discovery Interest is expressed
BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
- BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredName.value(), name);
+ BOOST_CHECK_EQUAL(discoveredVersion.has_value(), false);
+}
+
+BOOST_AUTO_TEST_CASE(NameWithVersion)
+{
+ // start with a name that already contains a version component
+ Name versionedName = Name(name).appendVersion(version);
+ run(versionedName);
+
+ // no version discovery Interest is expressed
+ BOOST_CHECK_EQUAL(face.sentInterests.size(), 0);
+
+ BOOST_CHECK_EQUAL(discoveredName.value(), versionedName);
BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
}
-BOOST_AUTO_TEST_CASE(DiscoverySuccess)
+BOOST_AUTO_TEST_CASE(Success)
{
- // express a discovery Interest to learn Data version
run(name);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
@@ -96,61 +109,66 @@
auto lastInterest = face.sentInterests.back();
BOOST_CHECK_EQUAL(lastInterest.getName(), discoveryInterest.getName());
- // Send back a metadata packet with a valid versioned name
+ // send back a metadata packet with a valid versioned name
MetadataObject mobject;
mobject.setVersionedName(Name(name).appendVersion(version));
face.receive(mobject.makeData(lastInterest.getName(), m_keyChain));
- advanceClocks(io, time::nanoseconds(1));
+ advanceClocks(io, 1_ns);
- BOOST_CHECK(isDiscoveryFinished);
BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
}
BOOST_AUTO_TEST_CASE(InvalidDiscoveredVersionedName)
{
- // issue a discovery Interest to learn Data version
run(name);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- // Send back a metadata packet with an invalid versioned name
+ // send back a metadata packet with an invalid versioned name
MetadataObject mobject;
mobject.setVersionedName(name);
face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
// finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK(!discoveredVersion.has_value());
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredName.has_value(), false);
+ BOOST_CHECK_EQUAL(discoveredVersion.has_value(), false);
}
BOOST_AUTO_TEST_CASE(InvalidMetadataPacket)
{
- // issue a discovery Interest to learn Data version
run(name);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- // Send back an invalid metadata packet
+ // send back an invalid metadata packet
Data data(face.sentInterests.back().getName());
data.setFreshnessPeriod(1_s);
data.setContentType(tlv::ContentType_Key);
face.receive(signData(data));
// finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK(!discoveredVersion.has_value());
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredName.has_value(), false);
+ BOOST_CHECK_EQUAL(discoveredVersion.has_value(), false);
}
-BOOST_AUTO_TEST_CASE(Timeout1)
+BOOST_AUTO_TEST_CASE(MaxRetriesExceeded)
{
- // issue a discovery Interest to learn Data version
+ opt.maxRetriesOnTimeoutOrNack = 3;
run(name);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- // timeout discovery Interests
- for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, opt.interestLifetime);
+ // timeout or nack discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack * 2; ++retries) {
+ if (retries % 2 == 0) {
+ advanceClocks(io, opt.interestLifetime);
+ }
+ else {
+ face.receive(makeNack(face.sentInterests.back(), lp::NackReason::DUPLICATE));
+ advanceClocks(io, 1_ns);
+ }
BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
@@ -160,20 +178,27 @@
advanceClocks(io, opt.interestLifetime);
// finish discovery process without a resolved version number
- BOOST_CHECK(isDiscoveryFinished);
- BOOST_CHECK(!discoveredVersion.has_value());
+ BOOST_CHECK_EQUAL(isDiscoveryFinished, true);
+ BOOST_CHECK_EQUAL(discoveredName.has_value(), false);
+ BOOST_CHECK_EQUAL(discoveredVersion.has_value(), false);
}
-BOOST_AUTO_TEST_CASE(Timeout2)
+BOOST_AUTO_TEST_CASE(SuccessAfterNackAndTimeout)
{
- // issue a discovery Interest to learn Data version
+ opt.maxRetriesOnTimeoutOrNack = 3;
run(name);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
- // timeout discovery Interests
- for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack; ++retries) {
- advanceClocks(io, opt.interestLifetime);
+ // timeout or nack discovery Interests
+ for (int retries = 0; retries < opt.maxRetriesOnTimeoutOrNack * 2; ++retries) {
+ if (retries % 2 == 0) {
+ advanceClocks(io, opt.interestLifetime);
+ }
+ else {
+ face.receive(makeNack(face.sentInterests.back(), lp::NackReason::DUPLICATE));
+ advanceClocks(io, 1_ns);
+ }
BOOST_CHECK_EQUAL(isDiscoveryFinished, false);
BOOST_REQUIRE_EQUAL(face.sentInterests.size(), retries + 2);
@@ -183,9 +208,8 @@
MetadataObject mobject;
mobject.setVersionedName(Name(name).appendVersion(version));
face.receive(mobject.makeData(face.sentInterests.back().getName(), m_keyChain));
- advanceClocks(io, time::nanoseconds(1));
+ advanceClocks(io, 1_ns);
- BOOST_CHECK(isDiscoveryFinished);
BOOST_CHECK_EQUAL(discoveredVersion.value(), version);
}