+
+TEST(Future, waitWithSemaphoreForTime) {
+ {
+ Promise<int> p;
+ Future<int> f = p.getFuture();
+ auto t = waitWithSemaphore(std::move(f),
+ std::chrono::microseconds(1));
+ EXPECT_FALSE(t.isReady());
+ p.setValue(1);
+ EXPECT_TRUE(t.isReady());
+ }
+ {
+ Promise<int> p;
+ Future<int> f = p.getFuture();
+ p.setValue(1);
+ auto t = waitWithSemaphore(std::move(f),
+ std::chrono::milliseconds(1));
+ EXPECT_TRUE(t.isReady());
+ }
+ {
+ vector<Future<bool>> v_fb;
+ v_fb.push_back(makeFuture(true));
+ v_fb.push_back(makeFuture(false));
+ auto f = whenAll(v_fb.begin(), v_fb.end());
+ auto t = waitWithSemaphore(std::move(f),
+ std::chrono::milliseconds(1));
+ EXPECT_TRUE(t.isReady());
+ EXPECT_EQ(2, t.value().size());
+ }
+ {
+ vector<Future<bool>> v_fb;
+ Promise<bool> p1;
+ Promise<bool> p2;
+ v_fb.push_back(p1.getFuture());
+ v_fb.push_back(p2.getFuture());
+ auto f = whenAll(v_fb.begin(), v_fb.end());
+ auto t = waitWithSemaphore(std::move(f),
+ std::chrono::milliseconds(1));
+ EXPECT_FALSE(t.isReady());
+ p1.setValue(true);
+ EXPECT_FALSE(t.isReady());
+ p2.setValue(true);
+ EXPECT_TRUE(t.isReady());
+ }
+ {
+ Promise<int> p;
+ Future<int> f = p.getFuture();
+ auto begin = std::chrono::system_clock::now();
+ auto t = waitWithSemaphore(std::move(f),
+ std::chrono::milliseconds(1));
+ auto end = std::chrono::system_clock::now();
+ EXPECT_TRUE( end - begin < std::chrono::milliseconds(2));
+ EXPECT_FALSE(t.isReady());
+ }
+ {
+ auto t = waitWithSemaphore(makeFuture(),
+ std::chrono::milliseconds(1));
+ EXPECT_TRUE(t.isReady());
+ }
+}