diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2015-05-18 16:59:15 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2015-05-19 17:00:05 -0400 |
commit | 1626ee600966ac99fd8a8045fb2a3a37cd6f9274 (patch) | |
tree | 896ba10a2a0913e8e8135782213f1881bb0ffb6f /src/mongo | |
parent | 9ab64834372d7d4c651bd41496f98afb7f44fbf7 (diff) | |
download | mongo-1626ee600966ac99fd8a8045fb2a3a37cd6f9274.tar.gz |
SERVER-17310 Remove use of boost::thread_group and boost::thread::interrupt from fail_point_test.
These behaviors do not have direct analogs in the C++11 thread support, so must be removed.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/util/fail_point_test.cpp | 68 |
1 files changed, 39 insertions, 29 deletions
diff --git a/src/mongo/util/fail_point_test.cpp b/src/mongo/util/fail_point_test.cpp index 5dfc185c585..9aa3e2d1889 100644 --- a/src/mongo/util/fail_point_test.cpp +++ b/src/mongo/util/fail_point_test.cpp @@ -156,9 +156,6 @@ namespace mongo_test { class FailPointStress: public mongo::unittest::Test { public: - FailPointStress(): _tasks(NULL) { - } - void setUp() { _fp.setMode(FailPoint::alwaysOn, 0, BSON("a" << 44)); } @@ -169,26 +166,29 @@ namespace mongo_test { } void startTest() { - verify(_tasks == NULL); + ASSERT_EQUALS(0U, _tasks.size()); - _tasks = new boost::thread_group(); - _tasks->add_thread(new boost::thread(blockTask, &_fp)); - _tasks->add_thread(new boost::thread(blockWithExceptionTask, &_fp)); - _tasks->add_thread(new boost::thread(simpleTask, &_fp)); - _tasks->add_thread(new boost::thread(flipTask, &_fp)); + _tasks.emplace_back(&FailPointStress::blockTask, this); + _tasks.emplace_back(&FailPointStress::blockWithExceptionTask, this); + _tasks.emplace_back(&FailPointStress::simpleTask, this); + _tasks.emplace_back(&FailPointStress::flipTask, this); } void stopTest() { - _tasks->interrupt_all(); - _tasks->join_all(); - delete _tasks; - _tasks = NULL; + { + boost::lock_guard<boost::mutex> lk(_mutex); + _inShutdown = true; + } + for (auto& t : _tasks) { + t.join(); + } + _tasks.clear(); } private: - static void blockTask(FailPoint* failPoint) { + void blockTask() { while (true) { - MONGO_FAIL_POINT_BLOCK((*failPoint), scopedFp) { + MONGO_FAIL_POINT_BLOCK(_fp, scopedFp) { const mongo::BSONObj& data = scopedFp.getData(); // Expanded ASSERT_EQUALS since the error is not being @@ -200,14 +200,16 @@ namespace mongo_test { } } - stdx::this_thread::interruption_point(); + boost::lock_guard<boost::mutex> lk(_mutex); + if (_inShutdown) + break; } } - static void blockWithExceptionTask(FailPoint* failPoint) { + void blockWithExceptionTask() { while (true) { try { - MONGO_FAIL_POINT_BLOCK((*failPoint), scopedFp) { + MONGO_FAIL_POINT_BLOCK(_fp, scopedFp) { const mongo::BSONObj& data = scopedFp.getData(); if (data["a"].numberInt() != 44) { @@ -222,32 +224,40 @@ namespace mongo_test { catch (const std::logic_error&) { } - stdx::this_thread::interruption_point(); - } + boost::lock_guard<boost::mutex> lk(_mutex); + if (_inShutdown) + break; + } } - static void simpleTask(FailPoint* failPoint) { + void simpleTask() { while (true) { - static_cast<void>(MONGO_FAIL_POINT((*failPoint))); - stdx::this_thread::interruption_point(); + static_cast<void>(MONGO_FAIL_POINT(_fp)); + boost::lock_guard<boost::mutex> lk(_mutex); + if (_inShutdown) + break; } } - static void flipTask(FailPoint* failPoint) { + void flipTask() { while (true) { - if(failPoint->shouldFail()) { - failPoint->setMode(FailPoint::off, 0); + if(_fp.shouldFail()) { + _fp.setMode(FailPoint::off, 0); } else { - failPoint->setMode(FailPoint::alwaysOn, 0, BSON("a" << 44)); + _fp.setMode(FailPoint::alwaysOn, 0, BSON("a" << 44)); } - stdx::this_thread::interruption_point(); + boost::lock_guard<boost::mutex> lk(_mutex); + if (_inShutdown) + break; } } FailPoint _fp; - boost::thread_group* _tasks; + std::vector<boost::thread> _tasks; + boost::mutex _mutex; + bool _inShutdown = false; }; TEST_F(FailPointStress, Basic) { |