Skip to content

Commit

Permalink
tests: avoid hardcoding control command names
Browse files Browse the repository at this point in the history
Change-Id: I98314d74d8f992e828af3d9b6c3e953ff4599bf9
  • Loading branch information
Pesa committed Jan 14, 2025
1 parent a745025 commit 1d2d337
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 72 deletions.
6 changes: 3 additions & 3 deletions tests/daemon/mgmt/cs-manager.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -55,7 +55,7 @@ BOOST_FIXTURE_TEST_SUITE(TestCsManager, CsManagerFixture)
BOOST_AUTO_TEST_CASE(Config)
{
using ndn::nfd::CsFlagBit;
const Name cmdPrefix("/localhost/nfd/cs/config");
const Name cmdPrefix = Name("/localhost/nfd").append(ndn::nfd::CsConfigCommand::getName());

// setup initial CS config
m_cs.setLimit(22129);
Expand Down Expand Up @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(Erase)
for (size_t i = 0; i < CsManager::ERASE_LIMIT + 1; ++i) {
m_cs.insert(*makeData(Name("/H").appendSequenceNumber(i)));
}
const Name cmdPrefix("/localhost/nfd/cs/erase");
const Name cmdPrefix = Name("/localhost/nfd").append(ndn::nfd::CsEraseCommand::getName());

// requested Name matches no Data
auto req = makeControlCommandRequest(cmdPrefix,
Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/mgmt/face-manager-command-fixture.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2024, Regents of the University of California,
* Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -109,12 +109,12 @@ FaceManagerCommandFixture::FaceManagerCommandFixture()
: node1(m_keyChain, 16363)
, node2(m_keyChain, 26363)
{
advanceClocks(1_ms, 5);
advanceClocks(1_ms, 10);
}

FaceManagerCommandFixture::~FaceManagerCommandFixture()
{
advanceClocks(1_ms, 5);
advanceClocks(1_ms, 10);
}

} // namespace nfd::tests
10 changes: 7 additions & 3 deletions tests/daemon/mgmt/face-manager-command-fixture.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -40,7 +40,6 @@ class FaceManagerCommandNode

~FaceManagerCommandNode();

public:
const Face*
findFaceByUri(const std::string& uri) const;

Expand All @@ -59,12 +58,17 @@ class FaceManagerCommandNode

class FaceManagerCommandFixture : public InterestSignerFixture
{
public:
protected:
FaceManagerCommandFixture();

~FaceManagerCommandFixture() override;

public:
static inline const Name CREATE_REQUEST = Name("/localhost/nfd").append(ndn::nfd::FaceCreateCommand::getName());
static inline const Name UPDATE_REQUEST = Name("/localhost/nfd").append(ndn::nfd::FaceUpdateCommand::getName());
static inline const Name DESTROY_REQUEST = Name("/localhost/nfd").append(ndn::nfd::FaceDestroyCommand::getName());

protected:
FaceManagerCommandNode node1; // used to test FaceManager
FaceManagerCommandNode node2; // acts as a remote endpoint
};
Expand Down
14 changes: 7 additions & 7 deletions tests/daemon/mgmt/face-manager-create-face.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2024, Regents of the University of California,
* Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -332,7 +332,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur
using FaceType = boost::mp11::mp_first<T>;
using CreateResult = boost::mp11::mp_second<T>;

Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
Interest req = makeControlCommandRequest(this->CREATE_REQUEST, FaceType::getParameters());

bool hasCallbackFired = false;
this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) {
Expand Down Expand Up @@ -417,7 +417,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixtur
});

this->node1.face.receive(req);
this->advanceClocks(1_ms, 5);
this->advanceClocks(1_ms, 10);

BOOST_CHECK(hasCallbackFired);
}
Expand All @@ -428,9 +428,9 @@ BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture)

{
// create face
Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters());
this->node1.face.receive(req);
this->advanceClocks(1_ms, 5);
this->advanceClocks(1_ms, 10);
}

// find the created face
Expand All @@ -439,7 +439,7 @@ BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture)

{
// re-create face
Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters());
Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters());

bool hasCallbackFired = false;
this->node1.face.onSendData.connect(
Expand All @@ -465,7 +465,7 @@ BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture)
});

this->node1.face.receive(req);
this->advanceClocks(1_ms, 5);
this->advanceClocks(1_ms, 10);

BOOST_CHECK(hasCallbackFired);
}
Expand Down
16 changes: 8 additions & 8 deletions tests/daemon/mgmt/face-manager-update-face.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2024, Regents of the University of California,
* Copyright (c) 2014-2025, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -82,7 +82,7 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture
void
createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
{
Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Interest req = makeControlCommandRequest(CREATE_REQUEST, createParams);

// if this creation if for on-demand face then create it on node2
FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
Expand Down Expand Up @@ -112,11 +112,11 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture
});

target.face.receive(req);
advanceClocks(1_ms, 5);
advanceClocks(1_ms, 10);

if (isForOnDemandFace) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
advanceClocks(1_ms, 10); // let node1 accept Interest and create on-demand face
}

BOOST_REQUIRE(hasCallbackFired);
Expand All @@ -127,7 +127,7 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture
bool isSelfUpdating,
const std::function<void(const ControlResponse& resp)>& checkResp)
{
Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Interest req = makeControlCommandRequest(UPDATE_REQUEST, requestParams);
if (isSelfUpdating) {
// Attach IncomingFaceIdTag to interest
req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Expand All @@ -147,7 +147,7 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture
});

this->node1.face.receive(req);
advanceClocks(1_ms, 5);
advanceClocks(1_ms, 10);
BOOST_REQUIRE(hasCallbackFired);
}

Expand All @@ -161,7 +161,7 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture

ControlParameters params;
params.setFaceId(faceId);
Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Interest req = makeControlCommandRequest(DESTROY_REQUEST, params);

bool hasCallbackFired = false;
signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Expand All @@ -178,7 +178,7 @@ class FaceManagerUpdateFixture : public FaceManagerCommandFixture
});

this->node1.face.receive(req);
advanceClocks(1_ms, 5);
advanceClocks(1_ms, 10);
BOOST_REQUIRE(hasCallbackFired);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/daemon/mgmt/face-manager.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "mgmt/face-manager.hpp"
#include "face/protocol-factory.hpp"

#include "manager-common-fixture.hpp"
#include "face-manager-command-fixture.hpp"
#include "tests/daemon/face/dummy-face.hpp"
#include "tests/daemon/face/dummy-transport.hpp"

Expand Down Expand Up @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(Existing)
auto addedFace = addFace(REMOVE_LAST_NOTIFICATION | SET_SCOPE_LOCAL); // clear notification for creation

auto parameters = ControlParameters().setFaceId(addedFace->getId());
auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
auto req = makeControlCommandRequest(FaceManagerCommandFixture::DESTROY_REQUEST, parameters);
receiveInterest(req);

BOOST_REQUIRE_EQUAL(m_responses.size(), 2); // one response and one notification
Expand All @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(Existing)
BOOST_AUTO_TEST_CASE(NonExisting)
{
auto parameters = ControlParameters().setFaceId(65535);
auto req = makeControlCommandRequest("/localhost/nfd/faces/destroy", parameters);
auto req = makeControlCommandRequest(FaceManagerCommandFixture::DESTROY_REQUEST, parameters);
receiveInterest(req);

BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Expand Down
27 changes: 15 additions & 12 deletions tests/daemon/mgmt/fib-manager.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class FibManagerFixture : public ManagerFixtureWithAuthenticator
}

protected:
static inline const Name ADD_NH_REQUEST = Name("/localhost/nfd")
.append(ndn::nfd::FibAddNextHopCommand::getName());
static inline const Name REMOVE_NH_REQUEST = Name("/localhost/nfd")
.append(ndn::nfd::FibRemoveNextHopCommand::getName());

Fib& m_fib;
FibManager m_manager;
};
Expand Down Expand Up @@ -152,8 +157,7 @@ BOOST_AUTO_TEST_SUITE(AddNextHop)

BOOST_AUTO_TEST_CASE(UnknownFaceId)
{
auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop",
makeParameters("hello", face::FACEID_NULL, 101));
auto req = makeControlCommandRequest(ADD_NH_REQUEST, makeParameters("hello", face::FACEID_NULL, 101));
receiveInterest(req);
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);

Expand All @@ -173,8 +177,7 @@ BOOST_AUTO_TEST_CASE(NameTooLong)
prefix.append("A");
}

auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop",
makeParameters(prefix, addFace()));
auto req = makeControlCommandRequest(ADD_NH_REQUEST, makeParameters(prefix, addFace()));
receiveInterest(req);

ControlResponse expected(414, "FIB entry prefix cannot exceed " +
Expand All @@ -194,7 +197,7 @@ BOOST_AUTO_TEST_CASE(ImplicitFaceId)
Name expectedName;
ControlResponse expectedResponse;
auto testAddNextHop = [&] (ControlParameters parameters, const FaceId& faceId) {
auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
auto req = makeControlCommandRequest(ADD_NH_REQUEST, parameters);
req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
m_responses.clear();
expectedName = req.getName();
Expand All @@ -219,7 +222,7 @@ BOOST_AUTO_TEST_CASE(InitialAdd)
BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);

auto parameters = makeParameters("hello", addedFaceId, 101);
auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
auto req = makeControlCommandRequest(ADD_NH_REQUEST, parameters);
receiveInterest(req);

BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Expand All @@ -235,7 +238,7 @@ BOOST_AUTO_TEST_CASE(ImplicitCost)

auto originalParameters = ControlParameters().setName("/hello").setFaceId(addedFaceId);
auto parameters = makeParameters("/hello", addedFaceId, 0);
auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", originalParameters);
auto req = makeControlCommandRequest(ADD_NH_REQUEST, originalParameters);
receiveInterest(req);

BOOST_REQUIRE_EQUAL(m_responses.size(), 1);
Expand All @@ -253,7 +256,7 @@ BOOST_AUTO_TEST_CASE(AddToExisting)
ControlResponse expectedResponse;
auto testAddNextHop = [&] (const ControlParameters& parameters) {
m_responses.clear();
auto req = makeControlCommandRequest("/localhost/nfd/fib/add-nexthop", parameters);
auto req = makeControlCommandRequest(ADD_NH_REQUEST, parameters);
expectedName = req.getName();
expectedResponse = makeResponse(200, "OK", parameters);
receiveInterest(req);
Expand Down Expand Up @@ -284,7 +287,7 @@ BOOST_AUTO_TEST_CASE(Basic)
ControlResponse expectedResponse;
auto testRemoveNextHop = [&] (const ControlParameters& parameters) {
m_responses.clear();
auto req = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
auto req = makeControlCommandRequest(REMOVE_NH_REQUEST, parameters);
expectedName = req.getName();
expectedResponse = makeResponse(200, "OK", parameters);
receiveInterest(req);
Expand Down Expand Up @@ -324,7 +327,7 @@ BOOST_AUTO_TEST_CASE(PrefixNotFound)
BOOST_REQUIRE_NE(addedFaceId, face::INVALID_FACEID);

auto parameters = makeParameters("hello", addedFaceId);
auto req = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
auto req = makeControlCommandRequest(REMOVE_NH_REQUEST, parameters);
receiveInterest(req);
BOOST_REQUIRE_EQUAL(m_responses.size(), 1);

Expand All @@ -343,7 +346,7 @@ BOOST_AUTO_TEST_CASE(ImplicitFaceId)
ControlResponse expectedResponse;
auto testWithImplicitFaceId = [&] (ControlParameters parameters, FaceId face) {
m_responses.clear();
auto req = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
auto req = makeControlCommandRequest(REMOVE_NH_REQUEST, parameters);
req.setTag(make_shared<lp::IncomingFaceIdTag>(face));
expectedName = req.getName();
expectedResponse = makeResponse(200, "OK", parameters.setFaceId(face));
Expand Down Expand Up @@ -376,7 +379,7 @@ BOOST_AUTO_TEST_CASE(RecordNotExist)
ControlResponse expectedResponse;
auto testRemoveNextHop = [&] (ControlParameters parameters) {
m_responses.clear();
auto req = makeControlCommandRequest("/localhost/nfd/fib/remove-nexthop", parameters);
auto req = makeControlCommandRequest(REMOVE_NH_REQUEST, parameters);
expectedName = req.getName();
expectedResponse = makeResponse(200, "OK", parameters);
receiveInterest(req);
Expand Down
Loading

0 comments on commit 1d2d337

Please sign in to comment.