TEST(SemiFuture, SimpleValue) { Promise<int> p; auto sf = p.getSemiFuture(); p.setValue(3); auto v = std::move(sf).value(); ASSERT_EQ(v, 3); }
TEST(SemiFuture, SimpleResult) { EventBase e2; Promise<int> p; auto sf = p.getSemiFuture(); p.setValue(3); auto v = std::move(sf).result(); ASSERT_EQ(v.value(), 3); }
TEST(SemiFuture, SimpleTimedGetTryViaFromSemiFuture) { TimedDrivableExecutor e2; Promise<folly::Unit> p; auto sf = p.getSemiFuture(); EXPECT_THROW( std::move(sf).via(&e2).getTryVia(&e2, std::chrono::milliseconds(100)), TimedOut); }
TEST(SemiFuture, SimpleTimedWait) { Promise<folly::Unit> p; auto sf = p.getSemiFuture(); sf.wait(std::chrono::milliseconds(100)); EXPECT_FALSE(sf.isReady()); p.setValue(); EXPECT_TRUE(sf.isReady()); }
TEST(SemiFuture, MakeFutureFromSemiFutureLValue) { folly::EventBase e; Promise<int> p; std::atomic<int> result{0}; auto f = p.getSemiFuture(); auto future = std::move(f).via(&e).then([&](int value) { result = value; return value; }); e.loop(); EXPECT_EQ(result, 0); EXPECT_FALSE(future.isReady()); p.setValue(42); e.loop(); EXPECT_TRUE(future.isReady()); ASSERT_EQ(future.value(), 42); ASSERT_EQ(result, 42); }
TEST(SemiFuture, SimpleResultThrow) { EventBase e2; Promise<folly::Unit> p; auto sf = p.getSemiFuture(); EXPECT_THROW(std::move(sf).result(), FutureNotReady); }
TEST(SemiFuture, SimpleValueThrow) { Promise<folly::Unit> p; auto sf = p.getSemiFuture(); EXPECT_THROW(std::move(sf).value(), FutureNotReady); }
TEST(SemiFuture, SimpleTimedGetTry) { Promise<folly::Unit> p; auto sf = p.getSemiFuture(); EXPECT_THROW(std::move(sf).getTry(std::chrono::milliseconds(100)), TimedOut); }
TEST(SemiFuture, MakeSemiFutureFromNotReadyFuture) { Promise<int> p; auto f = p.getSemiFuture(); EXPECT_THROW(f.value(), eggs_t); }
TEST(SemiFuture, MakeSemiFutureFromReadyFuture) { Promise<int> p; auto f = p.getSemiFuture(); EXPECT_FALSE(f.isReady()); p.setValue(42); EXPECT_TRUE(f.isReady()); }