upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/selftest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/selftest.cpp')
-rw-r--r--src/selftest.cpp66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index 54249b1..31c168f 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -968,6 +968,68 @@ static int RunWalletStorageSanitySelfTest()
968 return nFail == 0 ? 0 : 1; 968 return nFail == 0 ? 0 : 1;
969} 969}
970 970
971static int RunDbEnvReopenSelfTest()
972{
973 fflush(stdout);
974 printf("db-env-reopen self-test\n");
975
976 std::string tmp;
977 if (!MakeTempDir(tmp))
978 {
979 printf(" FAIL could not create a temporary data directory\n");
980 return 1;
981 }
982
983 int nFail = 0;
984 std::string strOldDataDir = strSetDataDir;
985 strSetDataDir = tmp;
986 printf(" temp datadir: %s\n", tmp.c_str());
987
988 try
989 {
990 for (int i = 0; i < 5; i++)
991 {
992 int64 nValue = 1000 + i;
993 {
994 CWalletDB walletdb("cr+");
995 nFail += Check(walletdb.WriteSetting("db-env-reopen-cycle", nValue),
996 "wallet setting can be written before shutdown") ? 0 : 1;
997 }
998
999 DBFlush(true);
1000
1001 int64 nRead = 0;
1002 {
1003 CWalletDB walletdb("r");
1004 nFail += Check(walletdb.ReadSetting("db-env-reopen-cycle", nRead),
1005 "wallet setting can be read after env reopen") ? 0 : 1;
1006 }
1007 nFail += Check(nRead == nValue,
1008 "reopened environment reads the last committed value") ? 0 : 1;
1009
1010 DBFlush(true);
1011 }
1012 }
1013 catch (const std::exception& e)
1014 {
1015 printf(" FAIL exception: %s\n", e.what());
1016 nFail++;
1017 }
1018 catch (...)
1019 {
1020 printf(" FAIL unknown exception\n");
1021 nFail++;
1022 }
1023
1024 DBFlush(true);
1025 strSetDataDir = strOldDataDir;
1026 RemoveTree(tmp);
1027 printf("%s (%d failure%s)\n", nFail == 0 ? "ALL TESTS PASSED" : "TESTS FAILED",
1028 nFail, nFail == 1 ? "" : "s");
1029 fflush(stdout);
1030 return nFail == 0 ? 0 : 1;
1031}
1032
971static void ClearWalletRuntimeForTest() 1033static void ClearWalletRuntimeForTest()
972{ 1034{
973 CRITICAL_BLOCK(cs_mapKeys) 1035 CRITICAL_BLOCK(cs_mapKeys)
@@ -2225,6 +2287,8 @@ int RunSelfTest(const std::string& name)
2225 return RunWalletFormatSelfTest(); 2287 return RunWalletFormatSelfTest();
2226 if (name == "wallet-storage-sanity") 2288 if (name == "wallet-storage-sanity")
2227 return RunWalletStorageSanitySelfTest(); 2289 return RunWalletStorageSanitySelfTest();
2290 if (name == "db-env-reopen")
2291 return RunDbEnvReopenSelfTest();
2228 if (name == "wallet-crypto") 2292 if (name == "wallet-crypto")
2229 return RunWalletCryptoSelfTest(); 2293 return RunWalletCryptoSelfTest();
2230 if (name == "wallet-encrypt") 2294 if (name == "wallet-encrypt")
@@ -2245,6 +2309,6 @@ int RunSelfTest(const std::string& name)
2245 return RunManagedTorSelfTest(); 2309 return RunManagedTorSelfTest();
2246 2310
2247 printf("Unknown self-test '%s'\n", name.c_str()); 2311 printf("Unknown self-test '%s'\n", name.c_str());
2248 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-storage-sanity, wallet-crypto, wallet-encrypt, wallet-portability, net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy, managed-tor\n"); 2312 printf("Known self-tests: wallet-keypool, wallet-hd, wallet-format, wallet-storage-sanity, db-env-reopen, wallet-crypto, wallet-encrypt, wallet-portability, net-message, consensus-limits, pool-stratum, parse-money, socks5-proxy, managed-tor\n");
2249 return 1; 2313 return 1;
2250} 2314}