Bitcoin Core 31.99.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#include <cstdint>
11
12using namespace node;
13
14namespace {
15void 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
22BOOST_AUTO_TEST_SUITE(caches_tests)
23
24BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
25{
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
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
BOOST_AUTO_TEST_SUITE_END()
Definition: messages.h:21
constexpr bool ShouldWarnOversizedDbCache(uint64_t dbcache, uint64_t total_ram) noexcept
Definition: caches.h:36
static constexpr uint64_t DEFAULT_DB_CACHE
-dbcache default (bytes)
Definition: caches.h:20
static constexpr uint64_t DBCACHE_WARNING_RESERVED_RAM
Reserved non-dbcache memory usage.
Definition: caches.h:22
static constexpr uint64_t MIN_DB_CACHE
min. -dbcache (bytes)
Definition: caches.h:18
#define BOOST_CHECK(expr)
Definition: object.cpp:16