From 26d81b1fdb41368c0c0226dc6e4054cd1b25c7b1 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Tue, 15 Feb 2022 13:51:12 +0000 Subject: [PATCH] Fix for unit test unchecked.multiple_get, do not use store.count() (#3738) When using rocksdb as the backend database, the count() method of the store cannot be trusted, it does not give accurate results. This problem is fixed by counting the blocks in the unchecked table one by one, by iterating through all of them, which should work for all db backends. resolves #3737 --- nano/core_test/block_store.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index ee6811b9..fef9e3dc 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -459,8 +459,22 @@ TEST (unchecked, multiple_get) unchecked.put (block3->previous (), block3); unchecked.put (block3->hash (), block3); // unchecked4 unchecked.put (block1->previous (), block3); // unchecked1 + + // count the number of blocks in the unchecked table by counting them one by one + // we cannot trust the count() method if the backend is rocksdb + auto count_unchecked_blocks_one_by_one = [&store, &unchecked] () { + size_t count = 0; + auto transaction = store->tx_begin_read (); + for (auto [i, end] = unchecked.full_range (transaction); i != end; ++i) + { + ++count; + } + return count; + }; + // Waits for the blocks to get saved in the database - ASSERT_TIMELY (5s, 8 == unchecked.count (store->tx_begin_read ())); + ASSERT_TIMELY (5s, 8 == count_unchecked_blocks_one_by_one ()); + std::vector unchecked1; // Asserts the entries will be found for the provided key auto transaction = store->tx_begin_read ();