Google テスト/モックを使用してブロックと非同期をテストしようとしています。
残念ながら、最初のケースで非同期が発生し、2 番目のケースで非同期が発生していることを確認するための何らかのテストを思い付くのに苦労しています。
std::future が正常に動作していることを確認する方法はありますか?
コード
#include <gtest/gtest.h>
#include <future>
static unsigned a_slow_calc()
{
sleep( 1 );
return 1u;
}
TEST( Test_future, Ensure_async )
{
// 1. immediately returns
std::future<unsigned> answer = std::async( a_slow_calc );
// 2. std::future::get BLOCKS until the result is ready
EXPECT_EQ( 1u, answer.get() );
}