Skip to content

Commit 7c8abf3

Browse files
furszyhebasto
andcommitted
bench: bugfix, properly release wallet before erasing directory
Since the wallet is appended to the global WalletContext during creation, merely calling 'reset()' on the benchmark shared_pointer is insufficient to destruct the wallet. This no destruction of the wallet results in the db connection remaining open, which was the cause of the 'fs::remove_all()' error in Windows. Co-Authored-By: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
1 parent dd42a5d commit 7c8abf3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/bench/wallet_create.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,25 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
3434
bilingual_str error_string;
3535
std::vector<bilingual_str> warnings;
3636

37-
fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
37+
auto wallet_path = fs::PathToString(test_setup->m_path_root / "test_wallet");
3838
bench.run([&] {
39-
auto wallet = CreateWallet(context, wallet_path.utf8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
39+
auto wallet = CreateWallet(context, wallet_path, /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
4040
assert(status == DatabaseStatus::SUCCESS);
4141
assert(wallet != nullptr);
4242

43-
// Cleanup
44-
wallet.reset();
43+
// Release wallet
44+
RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
45+
UnloadWallet(std::move(wallet));
4546
fs::remove_all(wallet_path);
4647
});
4748
}
4849

4950
static void WalletCreatePlain(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/false); }
5051
static void WalletCreateEncrypted(benchmark::Bench& bench) { WalletCreate(bench, /*encrypted=*/true); }
5152

52-
#ifndef _MSC_VER
53-
// TODO: Being built with MSVC, the fs::remove_all() call in
54-
// the WalletCreate() fails with the error "The process cannot
55-
// access the file because it is being used by another process."
5653
#ifdef USE_SQLITE
5754
BENCHMARK(WalletCreatePlain, benchmark::PriorityLevel::LOW);
5855
BENCHMARK(WalletCreateEncrypted, benchmark::PriorityLevel::LOW);
5956
#endif
60-
#endif
6157

6258
} // namespace wallet

0 commit comments

Comments
 (0)