caches_tests.cpp raw
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 #include <cstdint>
11
12 using namespace node;
13
14 namespace {
15 void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
16 {
17 BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
18 BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
19 }
20 } // namespace
21
22 BOOST_AUTO_TEST_SUITE(caches_tests)
23
24 BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
25 {
26 BOOST_CHECK(!ShouldWarnOversizedDbCache(MIN_DB_CACHE, 1_GiB));
27
28 // Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
29 CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, 1_GiB);
30 CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, DBCACHE_WARNING_RESERVED_RAM);
31
32 // Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
33 CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
34
35 for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
36 CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
37 }
38 }
39
40 BOOST_AUTO_TEST_SUITE_END()
41