X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Ffutures%2Ftest%2FInterruptTest.cpp;h=48ddc6da641600da267590719da43a0108598cb2;hp=1963c0a7b17af50887531c4a09f4667fce989d2f;hb=7da4ef82aee382777bb50aadd4af14a482739d10;hpb=5180b66230ee290a22bdba66f81e9f33e0216dd9 diff --git a/folly/futures/test/InterruptTest.cpp b/folly/futures/test/InterruptTest.cpp index 1963c0a7..48ddc6da 100644 --- a/folly/futures/test/InterruptTest.cpp +++ b/folly/futures/test/InterruptTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2014-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,26 @@ * limitations under the License. */ -#include - #include #include +#include +#include using namespace folly; TEST(Interrupt, raise) { - std::runtime_error eggs("eggs"); - Promise p; + using eggs_t = std::runtime_error; + Promise p; p.setInterruptHandler([&](const exception_wrapper& e) { - EXPECT_THROW(e.throwException(), decltype(eggs)); + EXPECT_THROW(e.throw_exception(), eggs_t); }); - p.getFuture().raise(eggs); + p.getFuture().raise(eggs_t("eggs")); } TEST(Interrupt, cancel) { - Promise p; + Promise p; p.setInterruptHandler([&](const exception_wrapper& e) { - EXPECT_THROW(e.throwException(), FutureCancellation); + EXPECT_THROW(e.throw_exception(), FutureCancellation); }); p.getFuture().cancel(); } @@ -41,7 +41,7 @@ TEST(Interrupt, cancel) { TEST(Interrupt, handleThenInterrupt) { Promise p; bool flag = false; - p.setInterruptHandler([&](const exception_wrapper& e) { flag = true; }); + p.setInterruptHandler([&](const exception_wrapper& /* e */) { flag = true; }); p.getFuture().cancel(); EXPECT_TRUE(flag); } @@ -50,25 +50,34 @@ TEST(Interrupt, interruptThenHandle) { Promise p; bool flag = false; p.getFuture().cancel(); - p.setInterruptHandler([&](const exception_wrapper& e) { flag = true; }); + p.setInterruptHandler([&](const exception_wrapper& /* e */) { flag = true; }); EXPECT_TRUE(flag); } TEST(Interrupt, interruptAfterFulfilNoop) { - Promise p; + Promise p; bool flag = false; - p.setInterruptHandler([&](const exception_wrapper& e) { flag = true; }); + p.setInterruptHandler([&](const exception_wrapper& /* e */) { flag = true; }); p.setValue(); p.getFuture().cancel(); EXPECT_FALSE(flag); } TEST(Interrupt, secondInterruptNoop) { - Promise p; + Promise p; int count = 0; - p.setInterruptHandler([&](const exception_wrapper& e) { count++; }); + p.setInterruptHandler([&](const exception_wrapper& /* e */) { count++; }); auto f = p.getFuture(); f.cancel(); f.cancel(); EXPECT_EQ(1, count); } + +TEST(Interrupt, withinTimedOut) { + Promise p; + Baton<> done; + p.setInterruptHandler([&](const exception_wrapper& /* e */) { done.post(); }); + p.getFuture().within(std::chrono::milliseconds(1)); + // Give it 100ms to time out and call the interrupt handler + EXPECT_TRUE(done.try_wait_for(std::chrono::milliseconds(100))); +}