X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ffutures%2Ftest%2FTimekeeperTest.cpp;h=4567b93c3f1b70558e29d4e477f1af7e252634ec;hb=d1c5974be19dcdcbf4f490eabd994fdc78da6086;hp=9c69253af9bf02340376b614e685f971f78b94de;hpb=d0856c87e70789282667a63015ac8c0509cf3e52;p=folly.git diff --git a/folly/futures/test/TimekeeperTest.cpp b/folly/futures/test/TimekeeperTest.cpp index 9c69253a..4567b93c 100644 --- a/folly/futures/test/TimekeeperTest.cpp +++ b/folly/futures/test/TimekeeperTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ #include +#include +#include #include using namespace folly; @@ -78,6 +80,14 @@ TEST(Timekeeper, futureSleep) { EXPECT_GE(now() - t1, one_ms); } +TEST(Timekeeper, futureSleepHandlesNullTimekeeperSingleton) { + Singleton::make_mock([] { return nullptr; }); + SCOPE_EXIT { + Singleton::make_mock(); + }; + EXPECT_THROW(futures::sleep(one_ms).get(), NoTimekeeper); +} + TEST(Timekeeper, futureDelayed) { auto t1 = now(); auto dur = makeFuture() @@ -133,6 +143,14 @@ TEST(Timekeeper, onTimeout) { EXPECT_TRUE(flag); } +TEST(Timekeeper, onTimeoutComplete) { + bool flag = false; + makeFuture(42) + .onTimeout(zero_ms, [&]{ flag = true; return -1; }) + .get(); + EXPECT_FALSE(flag); +} + TEST(Timekeeper, onTimeoutReturnsFuture) { bool flag = false; makeFuture(42).delayed(10 * one_ms) @@ -177,9 +195,11 @@ TEST(Timekeeper, executor) { std::atomic count{0}; }; - auto f = makeFuture(); + Promise p; ExecutorTester tester; - f.via(&tester).within(one_ms).then([&](){}).wait(); + auto f = p.getFuture().via(&tester).within(one_ms).then([&](){}); + p.setValue(); + f.wait(); EXPECT_EQ(2, tester.count); }