Skip to content

Commit

Permalink
test: coverage for netfulfilledman requests existence and expiration.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Feb 10, 2022
1 parent 42f76c9 commit be1c0fc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ BITCOIN_TESTS =\
test/miner_tests.cpp \
test/net_tests.cpp \
test/netbase_tests.cpp \
test/netfulfilledman_tests.cpp \
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \
test/prevector_tests.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(BITCOIN_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/multisig_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/net_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/netbase_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/netfulfilledman_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pmt_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/policyestimator_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/prevector_tests.cpp
Expand Down
41 changes: 41 additions & 0 deletions src/test/netfulfilledman_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2022 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include "netbase.h"
#include "test/test_pivx.h"
#include "tiertwo/netfulfilledman.h"
#include "utiltime.h"

#include <boost/test/unit_test.hpp>

BOOST_FIXTURE_TEST_SUITE(netfulfilledman_tests, RegTestingSetup)

BOOST_AUTO_TEST_CASE(netfulfilledman_simple_add_and_expire)
{
int64_t now = GetTime();
SetMockTime(now);

CNetFulfilledRequestManager fulfilledMan;
CService service = LookupNumeric("1.1.1.1", 9999);
std::string request = "request";
BOOST_ASSERT(!fulfilledMan.HasFulfilledRequest(service, request));

// Add request
fulfilledMan.AddFulfilledRequest(service, request);
// Verify that the request is there
BOOST_ASSERT(fulfilledMan.HasFulfilledRequest(service, request));

// Advance mock time to surpass FulfilledRequestExpireTime
SetMockTime(now + 60 * 60 + 1);

// Verify that the request exists and expired now
BOOST_CHECK(fulfilledMan.Size() == 1);
BOOST_CHECK(!fulfilledMan.HasFulfilledRequest(service, request));

// Verify request removal
fulfilledMan.CheckAndRemove();
BOOST_CHECK(fulfilledMan.Size() == 0);
}

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions src/tiertwo/netfulfilledman.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CNetFulfilledRequestManager
void Clear();

std::string ToString() const;
int Size() const { return WITH_LOCK(cs_mapFulfilledRequests, return mapFulfilledRequests.size();); }

void DoMaintenance();
};
Expand Down

0 comments on commit be1c0fc

Please sign in to comment.