Skip to content

Commit

Permalink
move wait for block to fault injector
Browse files Browse the repository at this point in the history
Summary:
We have some code in the SaplingBackingStore tests to poll the fault injector
until a fault is blocked. This is used to ensure that a fault is really blocked
before we continue. It prevents tests from being flakey.

I am going to need this in another test to prevent it from being flakey. So I
wanna move it to a shared place. Seems like putting it on the fault injector
directly makes sense.

This diff is moving code, no changes to the logic. Adding a test and some
changes in the next diffs.

Reviewed By: jdelliot

Differential Revision: D60931459

fbshipit-source-id: cfbb124edbb0645787a3c670fc0b8cc4c953dc9b
  • Loading branch information
Katie Mancini authored and facebook-github-bot committed Aug 8, 2024
1 parent 4a96be6 commit 9516594
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 17 additions & 1 deletion eden/common/utils/FaultInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

#include "eden/common/utils/FaultInjector.h"

#include <chrono>
#include <string_view>

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

using folly::SemiFuture;
using folly::Unit;

namespace facebook::eden {

using namespace std::chrono_literals;

FaultInjector::Fault::Fault(
std::string_view regex,
FaultBehavior&& b,
Expand Down Expand Up @@ -365,4 +369,16 @@ std::vector<std::string> FaultInjector::getBlockedFaults(
return results;
}

bool FaultInjector::waitUntilBlocked(
std::string_view keyClass,
std::chrono::milliseconds timeout) {
while (getBlockedFaults(keyClass).size() == 0 && timeout > 0s) {
timeout -= 1s;
/* sleep override */
sleep(1);
}

return getBlockedFaults(keyClass).size() != 0;
}

} // namespace facebook::eden
9 changes: 9 additions & 0 deletions eden/common/utils/FaultInjector.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ class FaultInjector {

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

/**
* Blocks up to timeout milliseconds waiting for a client to be blocked on
* the specified fault (keyClass). Returns true if a client is blocked, and
* false if the timeout was exceeded before a client was blocked.
*/
bool waitUntilBlocked(
std::string_view keyClass,
std::chrono::milliseconds timeout);

private:
struct Block {};
struct Delay {
Expand Down

0 comments on commit 9516594

Please sign in to comment.