TEST(Interrupt, interruptThenHandle) { Promise<int> p; bool flag = false; p.getFuture().cancel(); p.setInterruptHandler([&](const exception_wrapper& /* e */) { flag = true; }); EXPECT_TRUE(flag); }
TEST(Interrupt, cancel) { Promise<Unit> p; p.setInterruptHandler([&](const exception_wrapper& e) { EXPECT_THROW(e.throw_exception(), FutureCancellation); }); p.getFuture().cancel(); }
TEST(Interrupt, interruptAfterFulfilNoop) { Promise<Unit> p; bool flag = false; p.setInterruptHandler([&](const exception_wrapper& /* e */) { flag = true; }); p.setValue(); p.getFuture().cancel(); EXPECT_FALSE(flag); }
TEST(Interrupt, raise) { using eggs_t = std::runtime_error; Promise<Unit> p; p.setInterruptHandler([&](const exception_wrapper& e) { EXPECT_THROW(e.throw_exception(), eggs_t); }); p.getFuture().raise(eggs_t("eggs")); }
TEST(Interrupt, withinTimedOut) { Promise<int> 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 auto t = std::chrono::steady_clock::now() + std::chrono::milliseconds(100); EXPECT_TRUE(done.timed_wait(t)); }
TEST(Interrupt, secondInterruptNoop) { Promise<Unit> p; int count = 0; p.setInterruptHandler([&](const exception_wrapper& /* e */) { count++; }); auto f = p.getFuture(); f.cancel(); f.cancel(); EXPECT_EQ(1, count); }