Esempio n. 1
0
TEST_F(FutureTest, GetReturnsCorrectValue) {
    Future<int> f;

    pool.Enqueue([&f]() {
                     int result = f.Wait();
                     ASSERT_EQ(42, result);
                 });

    pool.Enqueue([&f]() {
                     f.Callback(42);
                 });

    pool.LoopUntilEmpty();
}
Esempio n. 2
0
TEST_F(FutureTest, IsFinishedIsSetAfterCallback) {
    Future<int> f;

    pool.Enqueue([&f]() {
                     std::this_thread::sleep_for(100ms);
                     int result = f.Wait();
                     ASSERT_EQ(42, result);
                 });

    pool.Enqueue([&f]() {
                     ASSERT_FALSE(f.is_finished());
                     f.Callback(42);

                     // let other thread run, but that one will wait 100ms
                     std::this_thread::sleep_for(10ns);
                     ASSERT_FALSE(f.is_finished());

                     // this should be after the the other thread called Get
                     std::this_thread::sleep_for(200ms);
                     ASSERT_TRUE(f.is_finished());
                 });

    pool.LoopUntilEmpty();
}