Bitcoin Core  31.0.0
P2P Digital Currency
caches_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://opensource.org/license/mit.
4 
5 #include <node/caches.h>
6 #include <util/byte_units.h>
7 
8 #include <boost/test/unit_test.hpp>
9 
10 using namespace node;
11 
12 BOOST_AUTO_TEST_SUITE(caches_tests)
13 
14 BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
15 {
16  // memory restricted setup - cap is DEFAULT_DB_CACHE (450 MiB)
17  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/4_MiB, /*total_ram=*/1024_MiB)); // Under cap
18  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1024_MiB)); // At cap
19  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1024_MiB)); // Over cap
20 
21  // 2 GiB RAM - cap is 75%
22  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2048_MiB)); // Under cap
23  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2048_MiB)); // Over cap
24 
25  if constexpr (SIZE_MAX == UINT64_MAX) {
26  // 4 GiB RAM - cap is 75%
27  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4096_MiB)); // Under cap
28  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4096_MiB)); // Over cap
29 
30  // 8 GiB RAM - cap is 75%
31  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8192_MiB)); // Under cap
32  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8192_MiB)); // Over cap
33 
34  // 16 GiB RAM - cap is 75%
35  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10'000_MiB, /*total_ram=*/16384_MiB)); // Under cap
36  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15'000_MiB, /*total_ram=*/16384_MiB)); // Over cap
37 
38  // 32 GiB RAM - cap is 75%
39  BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20'000_MiB, /*total_ram=*/32768_MiB)); // Under cap
40  BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30'000_MiB, /*total_ram=*/32768_MiB)); // Over cap
41  }
42 }
43 
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
BOOST_AUTO_TEST_SUITE_END()
constexpr bool ShouldWarnOversizedDbCache(size_t dbcache, size_t total_ram) noexcept
Definition: caches.h:32
Definition: messages.h:21
#define BOOST_CHECK(expr)
Definition: object.cpp:16