diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2018-05-30 12:59:38 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2018-09-07 11:36:21 -0400 |
commit | 2228531a653cbe1a0761dc433bb1446f3193a6b2 (patch) | |
tree | 493bccd41de8b0af40a9aad27737532fe4fd9fef /src/mongo | |
parent | 6e10ba77502c0ed24d9667ae56154a51f84f2273 (diff) | |
download | mongo-2228531a653cbe1a0761dc433bb1446f3193a6b2.tar.gz |
SERVER-35284 Construct unit test fixtures only in the child process in C++ death tests.
(cherry picked from commit 2bc714a6f9a9167e7c447bca6c684f1bce739b17)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/unittest/death_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/unittest/death_test.h | 9 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/mongo/unittest/death_test.cpp b/src/mongo/unittest/death_test.cpp index e78a1b6c840..e9def2e6e75 100644 --- a/src/mongo/unittest/death_test.cpp +++ b/src/mongo/unittest/death_test.cpp @@ -60,7 +60,8 @@ namespace mongo { namespace unittest { -DeathTestImpl::DeathTestImpl(std::unique_ptr<Test> test) : _test(std::move(test)) {} +DeathTestImpl::DeathTestImpl(stdx::function<std::unique_ptr<Test>()> makeTest) + : _makeTest(std::move(makeTest)) {} void DeathTestImpl::_doTest() { #if defined(_WIN32) @@ -121,7 +122,8 @@ void DeathTestImpl::_doTest() { checkSyscall(setrlimit(RLIMIT_CORE, &kNoCoreDump)); try { - _test->run(); + auto test = _makeTest(); + test->run(); } catch (const TestAssertionFailureException& tafe) { log() << "Caught test exception while expecting death: " << tafe; // To fail the test, we must exit with a successful error code, because the parent process diff --git a/src/mongo/unittest/death_test.h b/src/mongo/unittest/death_test.h index 01ab994b70c..ad25f3a3bf7 100644 --- a/src/mongo/unittest/death_test.h +++ b/src/mongo/unittest/death_test.h @@ -92,12 +92,12 @@ class DeathTestImpl : public Test { MONGO_DISALLOW_COPYING(DeathTestImpl); protected: - DeathTestImpl(std::unique_ptr<Test> test); + explicit DeathTestImpl(stdx::function<std::unique_ptr<Test>()> makeTest); private: - void _doTest() override; + void _doTest() final; virtual std::string getPattern() = 0; - std::unique_ptr<Test> _test; + const stdx::function<std::unique_ptr<Test>()> _makeTest; }; template <typename T> @@ -106,7 +106,8 @@ public: static const std::string pattern; template <typename... Args> - DeathTest(Args&&... args) : DeathTestImpl(stdx::make_unique<T>(std::forward<Args>(args)...)) {} + DeathTest(Args&&... args) + : DeathTestImpl([args...]() { return stdx::make_unique<T>(args...); }) {} private: std::string getPattern() override { |