From 951659416620d4eea975d0c1ec64abe3ebe9cd16 Mon Sep 17 00:00:00 2001 From: Katie Mancini Date: Thu, 8 Aug 2024 10:09:41 -0700 Subject: [PATCH] move wait for block to fault injector 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 --- eden/common/utils/FaultInjector.cpp | 18 +++++++++++++++++- eden/common/utils/FaultInjector.h | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/eden/common/utils/FaultInjector.cpp b/eden/common/utils/FaultInjector.cpp index 78f8d93..25674a8 100644 --- a/eden/common/utils/FaultInjector.cpp +++ b/eden/common/utils/FaultInjector.cpp @@ -7,15 +7,19 @@ #include "eden/common/utils/FaultInjector.h" +#include +#include + #include #include -#include using folly::SemiFuture; using folly::Unit; namespace facebook::eden { +using namespace std::chrono_literals; + FaultInjector::Fault::Fault( std::string_view regex, FaultBehavior&& b, @@ -365,4 +369,16 @@ std::vector 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 diff --git a/eden/common/utils/FaultInjector.h b/eden/common/utils/FaultInjector.h index 7af1779..49a4895 100644 --- a/eden/common/utils/FaultInjector.h +++ b/eden/common/utils/FaultInjector.h @@ -234,6 +234,15 @@ class FaultInjector { std::vector 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 {