Skip to content

Commit

Permalink
Improve the slow_test store.pruned_load to work the same way for all …
Browse files Browse the repository at this point in the history
…databases (#3666)

Previously, it did one thing for lmdb and another for rocksdb due to
rocksdb not having an accurate count of blocks.
The block counting is now done manually by iterating through all the blocks.
  • Loading branch information
dsiganos committed Jan 13, 2022
1 parent 943e9e6 commit 2752cfe
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions nano/slow_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@

using namespace std::chrono_literals;

/**
* function to count the block in the pruned store one by one
* we manually count the blocks one by one because the rocksdb count feature is not accurate
*/
size_t manually_count_pruned_blocks (nano::store & store)
{
size_t count = 0;
auto transaction = store.tx_begin_read ();
auto i = store.pruned.begin (transaction);
for (; i != store.pruned.end (); ++i)
{
++count;
}
return count;
}

TEST (system, generate_mass_activity)
{
nano::system system;
Expand Down Expand Up @@ -423,12 +439,19 @@ TEST (store, vote_load)
}
}

/**
* This test does the following:
* Creates a persistent database in the file system
* Adds 2 million random blocks to the database in chunks of 20 blocks per database transaction
* It then deletes half the blocks, soon after adding them
* Then it closes the database, reopens the database and checks that it still has the expected amount of blocks
*/
TEST (store, pruned_load)
{
nano::logger_mt logger;
auto path (nano::unique_path ());
constexpr auto num_pruned = 2000000;
auto const expected_result = nano::rocksdb_config::using_rocksdb_in_tests () ? num_pruned : num_pruned / 2;
auto const expected_result = num_pruned / 2;
constexpr auto batch_size = 20;
boost::unordered_set<nano::block_hash> hashes;
{
Expand All @@ -437,6 +460,7 @@ TEST (store, pruned_load)
for (auto i (0); i < num_pruned / batch_size; ++i)
{
{
// write a batch of random blocks to the pruned store
auto transaction (store->tx_begin_write ());
for (auto k (0); k < batch_size; ++k)
{
Expand All @@ -446,8 +470,8 @@ TEST (store, pruned_load)
hashes.insert (random_hash);
}
}
if (!nano::rocksdb_config::using_rocksdb_in_tests ())
{
// delete half of the blocks created above
auto transaction (store->tx_begin_write ());
for (auto k (0); !hashes.empty () && k < batch_size / 2; ++k)
{
Expand All @@ -457,15 +481,14 @@ TEST (store, pruned_load)
}
}
}
auto transaction (store->tx_begin_read ());
ASSERT_EQ (expected_result, store->pruned.count (transaction));
ASSERT_EQ (expected_result, manually_count_pruned_blocks (*store));
}

// Reinitialize store
{
auto store = nano::make_store (logger, path, nano::dev::constants);
ASSERT_FALSE (store->init_error ());
auto transaction (store->tx_begin_read ());
ASSERT_EQ (expected_result, store->pruned.count (transaction));
ASSERT_EQ (expected_result, manually_count_pruned_blocks (*store));
}
}

Expand Down

0 comments on commit 2752cfe

Please sign in to comment.