Branch data Line data Source code
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 [ + - + - : 7 : BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
+ - + - -
+ + - + -
+ - + - +
- - + + -
+ - + - +
- + - - +
+ - + - +
- + - + -
- + + - +
- + - + -
+ - - + +
- ]
15 : : {
16 : : // memory restricted setup - cap is DEFAULT_DB_CACHE (450 MiB)
17 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/4_MiB, /*total_ram=*/1024_MiB)); // Under cap
18 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1024_MiB)); // At cap
19 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1024_MiB)); // Over cap
20 : :
21 : : // 2 GiB RAM - cap is 75%
22 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2048_MiB)); // Under cap
23 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2048_MiB)); // Over cap
24 : :
25 : 1 : if constexpr (SIZE_MAX == UINT64_MAX) {
26 : : // 4 GiB RAM - cap is 75%
27 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4096_MiB)); // Under cap
28 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4096_MiB)); // Over cap
29 : :
30 : : // 8 GiB RAM - cap is 75%
31 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8192_MiB)); // Under cap
32 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8192_MiB)); // Over cap
33 : :
34 : : // 16 GiB RAM - cap is 75%
35 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10'000_MiB, /*total_ram=*/16384_MiB)); // Under cap
36 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15'000_MiB, /*total_ram=*/16384_MiB)); // Over cap
37 : :
38 : : // 32 GiB RAM - cap is 75%
39 [ + - ]: 1 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20'000_MiB, /*total_ram=*/32768_MiB)); // Under cap
40 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30'000_MiB, /*total_ram=*/32768_MiB)); // Over cap
41 : : }
42 : 1 : }
43 : :
44 : : BOOST_AUTO_TEST_SUITE_END()
|