Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Add backgroundWorkInterval() function to tests
Browse files Browse the repository at this point in the history
Add the function to TestCapability and TestCap definitions. Also remove unnecessary std:: prefix and update license messages.
  • Loading branch information
halfalicious committed Mar 16, 2019
1 parent e007a9a commit c254be9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
19 changes: 14 additions & 5 deletions test/unittests/libp2p/capability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ using namespace std;
using namespace dev;
using namespace dev::p2p;

namespace
{
chrono::milliseconds constexpr c_backgroundWorkInterval{1000};
}

class TestCapability : public CapabilityFace, public Worker
{
public:
explicit TestCapability(Host const& _host) : Worker("test"), m_host(_host) {}

std::string name() const override { return "test"; }
string name() const override { return "test"; }
unsigned version() const override { return 2; }
unsigned messageCount() const override { return UserPacket + 1; }
chrono::milliseconds backgroundWorkInterval() const override
{
return c_backgroundWorkInterval;
}

void onStarting() override {}
void onStopping() override {}
Expand Down Expand Up @@ -52,7 +61,7 @@ class TestCapability : public CapabilityFace, public Worker
_id, m_host.capabilityHost()->prep(_id, name(), s, UserPacket, 1) << _x);
}

std::pair<int, int> retrieveTestData(NodeID const& _id)
pair<int, int> retrieveTestData(NodeID const& _id)
{
int cnt = 0;
int checksum = 0;
Expand All @@ -67,8 +76,8 @@ class TestCapability : public CapabilityFace, public Worker
}

Host const& m_host;
std::unordered_map<NodeID, int> m_cntReceivedMessages;
std::unordered_map<NodeID, int> m_testSums;
unordered_map<NodeID, int> m_cntReceivedMessages;
unordered_map<NodeID, int> m_testSums;
};

TEST(p2p, capability)
Expand Down Expand Up @@ -122,7 +131,7 @@ TEST(p2p, capability)
thc2->sendTestMessage(host1.id(), i);

this_thread::sleep_for(chrono::seconds(target / 64 + 1));
std::pair<int, int> testData = thc1->retrieveTestData(host2.id());
pair<int, int> testData = thc1->retrieveTestData(host2.id());
EXPECT_EQ(target, testData.first);
EXPECT_EQ(checksum, testData.second);
}
44 changes: 18 additions & 26 deletions test/unittests/libp2p/peer.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file peer.cpp
* @author Gav Wood <[email protected]>
* @date 2014
* Peer Network test functions.
*/
// Aleth: Ethereum C++ client, tools and libraries.
// Copyright 2019 Aleth Authors.
// Licensed under the GNU General Public License, Version 3.

#include <libp2p/Capability.h>
#include <libp2p/Host.h>
Expand All @@ -33,13 +15,23 @@ using namespace dev;
using namespace dev::test;
using namespace dev::p2p;

namespace
{
chrono::milliseconds c_backgroundWorkInterval{1000};
}

class TestCap : public CapabilityFace, public Worker
{
public:
std::string name() const override { return "p2pTestCapability"; }
string name() const override { return "p2pTestCapability"; }
unsigned version() const override { return 2; }
unsigned messageCount() const override { return UserPacket + 1; }

chrono::milliseconds backgroundWorkInterval() const override
{
return c_backgroundWorkInterval;
}

void onStarting() override {}
void onStopping() override {}

Expand Down Expand Up @@ -153,11 +145,11 @@ BOOST_AUTO_TEST_CASE(registerCapabilityAfterNetworkStart)

BOOST_AUTO_TEST_CASE(saveNodes)
{
std::list<Host*> hosts;
list<Host*> hosts;
unsigned const c_step = 10;
unsigned const c_nodes = 6;
unsigned const c_peers = c_nodes - 1;
std::set<short unsigned> ports;
set<short unsigned> ports;

for (unsigned i = 0; i < c_nodes; ++i)
{
Expand Down Expand Up @@ -323,8 +315,8 @@ BOOST_AUTO_TEST_CASE(emptySharedPeer)
{
shared_ptr<Peer> p;
BOOST_REQUIRE(!p);
std::map<NodeID, std::shared_ptr<Peer>> peers;

map<NodeID, shared_ptr<Peer>> peers;
p = peers[NodeID()];
BOOST_REQUIRE(!p);

Expand Down

0 comments on commit c254be9

Please sign in to comment.