v30.3-roots.1 · Commit 2: [PATCH 02/68] feat(runtime): preserve Roots operator controls on Core 30.3
src/stats/test/stats_tests.cpp
Before: /dev/null · After: src/stats/test/stats_tests.cpp
File metadata
new file mode 100644 index 0000000000000000000000000000000000000000..77c21d595c10b22aa3bc8dcc23800185d9ae9158
Download original patch · Release notes
Diff rows 1–76 of 76. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/stats/test/stats_tests.cpp
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright (c) 2016 The Bitcoin Core developers
|
|
2
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
|
+
|
|
5
|
+
#include <stats/stats.h>
|
|
6
|
+
|
|
7
|
+
#include <test/util/setup_common.h>
|
|
8
|
+
#include <util/time.h>
|
|
9
|
+
|
|
10
|
+
#include <boost/test/unit_test.hpp>
|
|
11
|
+
|
|
12
|
+
BOOST_FIXTURE_TEST_SUITE(stats_tests, BasicTestingSetup)
|
|
13
|
+
|
|
14
|
+
BOOST_AUTO_TEST_CASE(stats)
|
|
15
|
+
{
|
|
16
|
+
CStats::DefaultStats()->setMaxMemoryUsageTarget(CStats::DEFAULT_MAX_STATS_MEMORY);
|
|
17
|
+
|
|
18
|
+
uint64_t start = GetTime();
|
|
19
|
+
SetMockTime(start);
|
|
20
|
+
|
|
21
|
+
CStats::DefaultStats()->addMempoolSample(0, 1, 1);
|
|
22
|
+
SetMockTime(start + 1);
|
|
23
|
+
CStats::DefaultStats()->addMempoolSample(0, 2, 2); //1second should be to short
|
|
24
|
+
SetMockTime(start + 5);
|
|
25
|
+
CStats::DefaultStats()->addMempoolSample(3, 4, 3);
|
|
26
|
+
|
|
27
|
+
uint64_t queryFromTime = start;
|
|
28
|
+
uint64_t queryToTime = start + 3600;
|
|
29
|
+
mempoolSamples_t samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
30
|
+
|
|
31
|
+
BOOST_CHECK_EQUAL(samples[0].m_time_delta, 0U);
|
|
32
|
+
BOOST_CHECK_EQUAL(samples[1].m_time_delta, 5U);
|
|
33
|
+
BOOST_CHECK_EQUAL(samples[1].m_tx_count, 3);
|
|
34
|
+
BOOST_CHECK_EQUAL(samples[1].m_dyn_mem_usage, 4);
|
|
35
|
+
|
|
36
|
+
// check retrieving a subset of the available samples
|
|
37
|
+
queryFromTime = start;
|
|
38
|
+
queryToTime = start;
|
|
39
|
+
samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
40
|
+
BOOST_CHECK_EQUAL(samples.size(), 1U);
|
|
41
|
+
|
|
42
|
+
// add some samples
|
|
43
|
+
for (int i = 0; i < 10000; i++) {
|
|
44
|
+
SetMockTime(start + 10 + i * 5);
|
|
45
|
+
CStats::DefaultStats()->addMempoolSample(i, i + 1, i + 2);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
queryFromTime = start + 3600;
|
|
49
|
+
queryToTime = start + 3600;
|
|
50
|
+
samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
51
|
+
BOOST_CHECK_EQUAL(samples.size(), 1U); //get a single sample
|
|
52
|
+
|
|
53
|
+
queryFromTime = start;
|
|
54
|
+
queryToTime = start + 3600;
|
|
55
|
+
samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
56
|
+
BOOST_CHECK(samples.size() >= 3600 / 5);
|
|
57
|
+
|
|
58
|
+
// reduce max memory and add 100 samples to ensure it triggers the cleanup
|
|
59
|
+
CStats::DefaultStats()->setMaxMemoryUsageTarget(10 * 1024);
|
|
60
|
+
for (int i = 10000; i < 10100; i++) {
|
|
61
|
+
SetMockTime(start + 10 + i * 5);
|
|
62
|
+
CStats::DefaultStats()->addMempoolSample(i, i + 1, i + 2);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
queryFromTime = start;
|
|
66
|
+
queryToTime = start + 100;
|
|
67
|
+
samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
68
|
+
BOOST_CHECK_EQUAL(samples.size(), 1U);
|
|
69
|
+
|
|
70
|
+
queryFromTime = 0; // no range limits
|
|
71
|
+
queryToTime = 0; // no range limits
|
|
72
|
+
samples = CStats::DefaultStats()->mempoolGetValuesInRange(queryFromTime, queryToTime);
|
|
73
|
+
BOOST_CHECK_EQUAL(samples.size() < 1000U, true);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
BOOST_AUTO_TEST_SUITE_END()
|