diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 3c125d1068..609707920d 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -124,12 +124,13 @@ public: private: struct AppBundle { - Application* app; + Application* app = nullptr; std::unique_ptr owned; - ManualTimeKeeper* timeKeeper; + ManualTimeKeeper* timeKeeper = nullptr; std::thread thread; std::unique_ptr client; + AppBundle() = default; AppBundle (beast::unit_test::suite& suite, std::unique_ptr config, std::unique_ptr logs); diff --git a/src/test/jtx/Env_test.cpp b/src/test/jtx/Env_test.cpp index db2d75f783..907a4d88a2 100644 --- a/src/test/jtx/Env_test.cpp +++ b/src/test/jtx/Env_test.cpp @@ -749,6 +749,22 @@ public: } } + void testExceptionalShutdown() + { + except( + [this] + { + jtx::Env env {*this, + jtx::envconfig([](std::unique_ptr cfg) + { + (*cfg).deprecatedClearSection("port_rpc"); + return cfg; + })}; + } + ); + pass(); + } + void run() override { @@ -771,6 +787,7 @@ public: testResignSigned(); testSignAndSubmit(); testFeatures(); + testExceptionalShutdown(); } }; diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 44ca0e9ec6..3ebd71c19d 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -59,6 +59,7 @@ namespace jtx { Env::AppBundle::AppBundle(beast::unit_test::suite& suite, std::unique_ptr config, std::unique_ptr logs) + : AppBundle() { using namespace beast::severities; // Use kFatal threshold to reduce noise from STObject. @@ -89,9 +90,13 @@ Env::AppBundle::~AppBundle() client.reset(); // Make sure all jobs finish, otherwise tests // might not get the coverage they expect. - app->getJobQueue().rendezvous(); - app->signalStop(); - thread.join(); + if (app) + { + app->getJobQueue().rendezvous(); + app->signalStop(); + } + if (thread.joinable()) + thread.join(); // Remove the debugLogSink before the suite goes out of scope. setDebugLogSink (nullptr);