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=*/1_GiB)); // Under cap
18 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1_GiB)); // At cap
19 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1_GiB)); // Over cap
20 : :
21 : : // 2 GiB RAM - cap is 75%
22 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2_GiB)); // Under cap
23 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2_GiB)); // Over cap
24 : :
25 : : // 4 GiB RAM - cap is 75%
26 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4_GiB)); // Under cap
27 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4_GiB)); // Over cap
28 : :
29 : : // 8 GiB RAM - cap is 75%
30 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8_GiB)); // Under cap
31 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8_GiB)); // Over cap
32 : :
33 : : // 16 GiB RAM - cap is 75%
34 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10_GiB, /*total_ram=*/16_GiB)); // Under cap
35 [ + - ]: 2 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15_GiB, /*total_ram=*/16_GiB)); // Over cap
36 : :
37 : : // 32 GiB RAM - cap is 75%
38 [ + - ]: 2 : BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20_GiB, /*total_ram=*/32_GiB)); // Under cap
39 [ + - ]: 1 : BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30_GiB, /*total_ram=*/32_GiB)); // Over cap
40 : 1 : }
41 : :
42 : : BOOST_AUTO_TEST_SUITE_END()
|