Fix broken promise error in folly::retrying
[folly.git] / folly / futures / test / RetryingTest.cpp
index 43a15ea2221754cdaec099821e8e061600fb5bab..59eb3e0156a6110686c26a572ebd48a3ebf0dca8 100644 (file)
@@ -75,6 +75,27 @@ TEST(RetryingTest, basic) {
   EXPECT_EQ(2, r.value());
 }
 
+TEST(RetryingTest, future_factory_throws) {
+  struct ReturnedException : exception {};
+  struct ThrownException : exception {};
+  auto result = futures::retrying(
+                    [](size_t n, const exception_wrapper&) { return n < 2; },
+                    [](size_t n) {
+                      switch (n) {
+                        case 0:
+                          return makeFuture<size_t>(
+                              make_exception_wrapper<ReturnedException>());
+                        case 1:
+                          throw ThrownException();
+                        default:
+                          return makeFuture(n);
+                      }
+                    })
+                    .wait()
+                    .getTry();
+  EXPECT_THROW(result.throwIfFailed(), ThrownException);
+}
+
 TEST(RetryingTest, policy_future) {
   atomic<size_t> sleeps {0};
   auto r = futures::retrying(
@@ -146,7 +167,9 @@ TEST(RetryingTest, large_retries) {
   rlimit newMemLimit;
   newMemLimit.rlim_cur = std::min(1UL << 30, oldMemLimit.rlim_max);
   newMemLimit.rlim_max = oldMemLimit.rlim_max;
-  PCHECK(setrlimit(RLIMIT_AS, &newMemLimit) == 0);
+  if (!folly::kIsSanitizeAddress) { // ASAN reserves outside of the rlimit
+    PCHECK(setrlimit(RLIMIT_AS, &newMemLimit) == 0);
+  }
   SCOPE_EXIT {
     PCHECK(setrlimit(RLIMIT_AS, &oldMemLimit) == 0);
   };