Skip to content

Commit

Permalink
expose the number of blocked faults
Browse files Browse the repository at this point in the history
Summary: Added a public method for FaultInjector so we can inspect the currently blocked checks. This allows us to test better when we need to make sure a certain check is currently blocking before we can do other operations.

Reviewed By: kmancini

Differential Revision: D58213922

fbshipit-source-id: 797289c8b22f7f57d722506f36cb542a466ea8fa
  • Loading branch information
lXXXw authored and facebook-github-bot committed Jun 14, 2024
1 parent c586729 commit 1cc8fd6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
16 changes: 16 additions & 0 deletions eden/common/utils/FaultInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <folly/Overload.h>
#include <folly/logging/xlog.h>
#include <string_view>

using folly::SemiFuture;
using folly::Unit;
Expand Down Expand Up @@ -349,4 +350,19 @@ size_t FaultInjector::unblockAllImpl(
return numUnblocked;
}

std::vector<std::string> FaultInjector::getBlockedFaults(
std::string_view keyClass) {
auto state = state_.rlock();
std::vector<std::string> results;
auto classIter = state->blockedChecks.find(keyClass);
if (classIter == state->blockedChecks.end()) {
return results;
}

for (auto& blockedCheck : classIter->second) {
results.emplace_back(blockedCheck.keyValue);
}
return results;
}

} // namespace facebook::eden
2 changes: 2 additions & 0 deletions eden/common/utils/FaultInjector.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class FaultInjector {
size_t unblockAll();
size_t unblockAllWithError(folly::exception_wrapper error);

std::vector<std::string> getBlockedFaults(std::string_view keyClass);

private:
struct Block {};
struct Delay {
Expand Down
39 changes: 38 additions & 1 deletion eden/common/utils/test/FaultInjectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TEST(FaultInjector, blocking) {
future1 = fi.checkAsync("mount", "/x/y/z");
EXPECT_FALSE(future1.isReady());
future2 = fi.checkAsync("mount", "/a/b/c");
EXPECT_FALSE(future1.isReady());
EXPECT_FALSE(future2.isReady());

// Unblock just one call with an error
countUnblocked =
Expand Down Expand Up @@ -166,3 +166,40 @@ TEST(FaultInjector, joinedKey) {
fi.checkAsync("my_fault", "foo", "baz").get();
fi.check("my_fault", "bar", "foo");
}

TEST(FaultInjector, getBlockedFaults) {
FaultInjector fi(true);
fi.injectBlock("mount", ".*");

auto future1 = fi.checkAsync("mount", "/x/y/z");
EXPECT_FALSE(future1.isReady());

auto inspectRes = fi.getBlockedFaults("mount");
EXPECT_EQ(1, inspectRes.size());

fi.unblock("mount", ".*");
ASSERT_NE(future1.isReady(), detail::kImmediateFutureAlwaysDefer);

inspectRes = fi.getBlockedFaults("mount");
EXPECT_EQ(0, inspectRes.size());
}

TEST(FaultInjector, disabledFaultInjector) {
FaultInjector fi(false);

EXPECT_THROW_RE(fi.injectBlock("mount", ".*");
, std::runtime_error, "fault injection is disabled");

auto inspectRes = fi.getBlockedFaults("mount");
EXPECT_EQ(0, inspectRes.size());
}

TEST(FaultInjector, getBlockedFaultsWhenErrorInjected) {
FaultInjector fi(true);
fi.injectError("mount", ".*", std::runtime_error("fail"));
auto future = fi.checkAsync("mount", "/x/y/z");

EXPECT_THROW_RE(std::move(future).get(), std::runtime_error, "fail");
auto inspectRes = fi.getBlockedFaults("mount");
EXPECT_EQ(0, inspectRes.size());
}

0 comments on commit 1cc8fd6

Please sign in to comment.