mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
test: indexes, avoid creating threads when sync runs synchronously
The indexes test call StartBackgroundSync(), which spawns a thread to run Sync(), only for the test thread to wait for it to complete by calling IndexWaitSynced(). So, since the sync is performed synchronously, we can skip the extra thread creation entirely and call Sync() directly.
This commit is contained in:
@@ -6,7 +6,6 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL
|
||||
blockfilter.cpp
|
||||
coins.cpp
|
||||
coverage.cpp
|
||||
index.cpp
|
||||
json.cpp
|
||||
logging.cpp
|
||||
mining.cpp
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/util/index.h>
|
||||
|
||||
#include <index/base.h>
|
||||
#include <util/check.h>
|
||||
#include <util/signalinterrupt.h>
|
||||
#include <util/time.h>
|
||||
|
||||
void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt)
|
||||
{
|
||||
while (!index.BlockUntilSyncedToCurrentChain()) {
|
||||
// Assert shutdown was not requested to abort the test, instead of looping forever, in case
|
||||
// there was an unexpected error in the index that caused it to stop syncing and request a shutdown.
|
||||
Assert(!interrupt);
|
||||
|
||||
UninterruptibleSleep(100ms);
|
||||
}
|
||||
assert(index.GetSummary().synced);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_UTIL_INDEX_H
|
||||
#define BITCOIN_TEST_UTIL_INDEX_H
|
||||
|
||||
class BaseIndex;
|
||||
namespace util {
|
||||
class SignalInterrupt;
|
||||
} // namespace util
|
||||
|
||||
/** Block until the index is synced to the current chain */
|
||||
void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt);
|
||||
|
||||
#endif // BITCOIN_TEST_UTIL_INDEX_H
|
||||
Reference in New Issue
Block a user