Skip to content

Commit 38fbb57

Browse files
committed
Merge #16294: qt: test: Create at most one testing setup
faa1e0f qt: test: Create at most one testing setup (MarcoFalke) Pull request description: It is assumed that ideally only one BasicTestingSetup exists at any point in time for each process (due to use of globals). This assumption is violated in the GUI tests, as a testing setup is created as the first step of the `main` function and then (sometimes) another one for the following test cases. So, the gui tests create two testing setups: * `BasicTestingSetup` in `main` (added in fa4a04a) * a testing setup for individual test cases Avoid that by destructing the testing setup in main after creation and then move the explicit `ECC_Stop` to the only places where it is needed (before and after `apptests`). ACKs for top commit: laanwj: code review ACK faa1e0f Tree-SHA512: b8edceb7e2a8749e1de3ea80bc20b6fb7d4390bf366bb9817206ada3dc8669a91416f4803c22a0e6c636c514e0c858dcfe04523221f8851b10deaf472f107d82
2 parents 7f985d6 + faa1e0f commit 38fbb57

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

src/qt/test/apptests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <qt/networkstyle.h>
1212
#include <qt/rpcconsole.h>
1313
#include <shutdown.h>
14+
#include <test/setup_common.h>
15+
#include <univalue.h>
1416
#include <validation.h>
1517

1618
#if defined(HAVE_CONFIG_H)
@@ -26,8 +28,6 @@
2628
#include <QtGlobal>
2729
#include <QtTest/QtTestWidgets>
2830
#include <QtTest/QtTestGui>
29-
#include <string>
30-
#include <univalue.h>
3131

3232
namespace {
3333
//! Call getblockchaininfo RPC and check first field of JSON output.
@@ -62,6 +62,7 @@ void AppTests::appTests()
6262
}
6363
#endif
6464

65+
BasicTestingSetup test{CBaseChainParams::REGTEST}; // Create a temp data directory to backup the gui settings to
6566
ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference
6667
LogInstance().DisconnectTestLogger();
6768

src/qt/test/paymentservertests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <random.h>
1414
#include <script/script.h>
1515
#include <script/standard.h>
16-
#include <util/system.h>
16+
#include <test/setup_common.h>
1717
#include <util/strencodings.h>
1818

1919
#include <openssl/x509.h>
@@ -66,7 +66,7 @@ static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsig
6666

6767
void PaymentServerTests::paymentServerTests()
6868
{
69-
SelectParams(CBaseChainParams::MAIN);
69+
BasicTestingSetup testing_setup(CBaseChainParams::MAIN);
7070
auto node = interfaces::MakeNode();
7171
OptionsModel optionsModel(*node);
7272
PaymentServer* server = new PaymentServer(nullptr, false);

src/qt/test/rpcnestedtests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ void RPCNestedTests::rpcNestedTests()
3434
tableRPC.appendCommand("rpcNestedTest", &vRPCCommands[0]);
3535
//mempool.setSanityCheck(1.0);
3636

37-
ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference
38-
LogInstance().DisconnectTestLogger();
39-
4037
TestingSetup test;
4138

4239
if (RPCIsInWarmup(nullptr)) SetRPCWarmupFinished();

src/qt/test/test_main.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
4242
#endif
4343
#endif
4444

45-
extern void noui_connect();
46-
4745
// This is all you need to run all the tests
4846
int main(int argc, char *argv[])
4947
{
50-
BasicTestingSetup test{CBaseChainParams::REGTEST};
48+
// Initialize persistent globals with the testing setup state for sanity.
49+
// E.g. -datadir in gArgs is set to a temp directory dummy value (instead
50+
// of defaulting to the default datadir), or globalChainParams is set to
51+
// regtest params.
52+
//
53+
// All tests must use their own testing setup (if needed).
54+
{
55+
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
56+
}
5157

5258
auto node = interfaces::MakeNode();
5359

src/test/setup_common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
7373
const CChainParams& chainparams = Params();
7474
// Ideally we'd move all the RPC tests to the functional testing framework
7575
// instead of unit tests, but for now we need these here.
76-
7776
RegisterAllCoreRPCCommands(tableRPC);
7877

7978
// We have to run a scheduler thread to prevent ActivateBestChain

0 commit comments

Comments
 (0)