summaryrefslogtreecommitdiff
path: root/src/mongo/util/fail_point_test.cpp
diff options
context:
space:
mode:
authorBilly Donahue <billy.donahue@mongodb.com>2019-09-10 19:03:36 +0000
committerevergreen <evergreen@mongodb.com>2019-09-10 19:03:36 +0000
commit5a0f718e1309a4484580d8038016d043ef3b887f (patch)
tree7a331d57ba6e33e61f96ed69b2aa387003a039ab /src/mongo/util/fail_point_test.cpp
parentb9e29cd56ebc9aca06f68eeeda7c523d3dfd6d41 (diff)
downloadmongo-5a0f718e1309a4484580d8038016d043ef3b887f.tar.gz
SERVER-43119 FailPoint cleanup
- Don't use MONGO_INITIALIZER to declare each fail point. We only need one init task in total: freeze and iterate the registry. - remove MONGO_FAIL_POINT_DECLARE macro (extern) - remove MONGO_FAIL_POINT_SHOULD_FAIL macro (FailPoint::shouldFail) - remove MONGO_FAIL_POINT_BLOCK_IF (FailPoint::executeIf) - remove MONGO_FAIL_POINT_BLOCK (FailPoint::execute) - clean up FailPointRegistry and fail_point_service implementation.
Diffstat (limited to 'src/mongo/util/fail_point_test.cpp')
-rw-r--r--src/mongo/util/fail_point_test.cpp74
1 files changed, 25 insertions, 49 deletions
diff --git a/src/mongo/util/fail_point_test.cpp b/src/mongo/util/fail_point_test.cpp
index 0a32ec45777..1880b0d18a1 100644
--- a/src/mongo/util/fail_point_test.cpp
+++ b/src/mongo/util/fail_point_test.cpp
@@ -46,7 +46,6 @@
using mongo::BSONObj;
using mongo::FailPoint;
using mongo::FailPointEnableBlock;
-using mongo::getGlobalFailPointRegistry;
namespace stdx = mongo::stdx;
namespace mongo_test {
@@ -60,7 +59,7 @@ TEST(FailPoint, AlwaysOn) {
failPoint.setMode(FailPoint::alwaysOn);
ASSERT(failPoint.shouldFail());
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
+ if (auto scopedFp = failPoint.scoped(); MONGO_unlikely(scopedFp.isActive())) {
ASSERT(scopedFp.getData().isEmpty());
}
@@ -85,11 +84,7 @@ TEST(FailPoint, NTimes) {
TEST(FailPoint, BlockOff) {
FailPoint failPoint;
bool called = false;
-
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
- called = true;
- }
-
+ failPoint.execute([&](const BSONObj&) { called = true; });
ASSERT_FALSE(called);
}
@@ -98,9 +93,7 @@ TEST(FailPoint, BlockAlwaysOn) {
failPoint.setMode(FailPoint::alwaysOn);
bool called = false;
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
- called = true;
- }
+ failPoint.execute([&](const BSONObj&) { called = true; });
ASSERT(called);
}
@@ -111,9 +104,7 @@ TEST(FailPoint, BlockNTimes) {
size_t counter = 0;
for (size_t x = 0; x < 10; x++) {
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
- counter++;
- }
+ failPoint.execute([&](auto&&...) { counter++; });
}
ASSERT_EQUALS(1U, counter);
@@ -125,9 +116,8 @@ TEST(FailPoint, BlockWithException) {
bool threw = false;
try {
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
- throw std::logic_error("BlockWithException threw");
- }
+ failPoint.execute(
+ [&](const BSONObj&) { throw std::logic_error("BlockWithException threw"); });
} catch (const std::logic_error&) {
threw = true;
}
@@ -142,9 +132,7 @@ TEST(FailPoint, SetGetParam) {
FailPoint failPoint;
failPoint.setMode(FailPoint::alwaysOn, 0, BSON("x" << 20));
- MONGO_FAIL_POINT_BLOCK(failPoint, scopedFp) {
- ASSERT_EQUALS(20, scopedFp.getData()["x"].numberInt());
- }
+ failPoint.execute([&](const BSONObj& data) { ASSERT_EQUALS(20, data["x"].numberInt()); });
}
class FailPointStress : public mongo::unittest::Test {
@@ -181,9 +169,7 @@ public:
private:
void blockTask() {
while (true) {
- MONGO_FAIL_POINT_BLOCK(_fp, scopedFp) {
- const mongo::BSONObj& data = scopedFp.getData();
-
+ _fp.execute([](const BSONObj& data) {
// Expanded ASSERT_EQUALS since the error is not being
// printed out properly
if (data["a"].numberInt() != 44) {
@@ -191,7 +177,7 @@ private:
<< " - data: " << data << std::endl;
ASSERT(false);
}
- }
+ });
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (_inShutdown)
@@ -202,9 +188,7 @@ private:
void blockWithExceptionTask() {
while (true) {
try {
- MONGO_FAIL_POINT_BLOCK(_fp, scopedFp) {
- const mongo::BSONObj& data = scopedFp.getData();
-
+ _fp.execute([](const BSONObj& data) {
if (data["a"].numberInt() != 44) {
mongo::error() << "blockWithExceptionTask thread detected anomaly"
<< " - data: " << data << std::endl;
@@ -212,7 +196,7 @@ private:
}
throw std::logic_error("blockWithExceptionTask threw");
- }
+ });
} catch (const std::logic_error&) {
}
@@ -224,7 +208,7 @@ private:
void simpleTask() {
while (true) {
- static_cast<void>(MONGO_FAIL_POINT(_fp));
+ static_cast<void>(MONGO_unlikely(_fp.shouldFail()));
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (_inShutdown)
break;
@@ -403,7 +387,7 @@ TEST(FailPoint, parseBSONValidDataSucceeds) {
}
TEST(FailPoint, FailPointBlockBasicTest) {
- auto failPoint = getGlobalFailPointRegistry()->getFailPoint("dummy");
+ auto failPoint = mongo::globalFailPointRegistry().find("dummy");
ASSERT_FALSE(failPoint->shouldFail());
@@ -418,33 +402,25 @@ TEST(FailPoint, FailPointBlockBasicTest) {
TEST(FailPoint, FailPointBlockIfBasicTest) {
FailPoint failPoint;
failPoint.setMode(FailPoint::nTimes, 1, BSON("skip" << true));
-
{
bool hit = false;
-
- MONGO_FAIL_POINT_BLOCK_IF(failPoint, scopedFp, [&](const BSONObj& obj) {
- hit = obj["skip"].trueValue();
- return false;
- }) {
- ASSERT(!"shouldn't get here");
- }
-
+ failPoint.executeIf([](const BSONObj&) { ASSERT(!"shouldn't get here"); },
+ [&hit](const BSONObj& obj) {
+ hit = obj["skip"].trueValue();
+ return false;
+ });
ASSERT(hit);
}
-
{
bool hit = false;
-
- MONGO_FAIL_POINT_BLOCK_IF(failPoint, scopedFp, [](auto) { return true; }) {
- hit = true;
- ASSERT(!scopedFp.getData().isEmpty());
- }
-
+ failPoint.executeIf(
+ [&hit](const BSONObj& data) {
+ hit = true;
+ ASSERT(!data.isEmpty());
+ },
+ [](const BSONObj&) { return true; });
ASSERT(hit);
}
-
- MONGO_FAIL_POINT_BLOCK_IF(failPoint, scopedFp, [](auto) { return true; }) {
- ASSERT(!"shouldn't get here");
- }
+ failPoint.executeIf([](auto&&) { ASSERT(!"shouldn't get here"); }, [](auto&&) { return true; });
}
} // namespace mongo_test