TTB_TEST_FUNC(BlockingWait)
{
SomeSimulatedObject a("SimObjectA");
a._SetOption(TTB::Option::oSYNC, "CalculateSomething");
a._SetOption(TTB::Option::oBLOCKING, "CalculateSomething",
TTB::OptionType::AFTER_N_CALLS_ACTIVE_ONCE, 3);
TTB_INFO("\nCalling CalculateSomething asynchronously 5 times, block on 3rd call");
TTB_INIT_SYNC(3);
std::thread t([&]()
{
int result;
a.CalculateSomething(17, result);
a.CalculateSomething(18, result);
a.CalculateSomething(19, result);
a.CalculateSomething(20, result);
a.CalculateSomething(21, result);
});
TTB_WAIT_SYNC();
TTB_EXP("CalculateSomething in_val=17 out_val=34 (SimObjectA)");
TTB_EXP("CalculateSomething in_val=18 out_val=36 (SimObjectA)");
TTB_EXP("CalculateSomething-Start in_val=19 (SimObjectA)");
a._SetOption(TTB::Option::oERROR, "CalculateSomething", TTB::OptionType::ACTIVE_ONCE);
TTB_INFO("\nNow continuing the interrupted call to CalculateSomething with error and proceed the call sequence");
TTB_INIT_SYNC(3);
a._ContinueExecution("CalculateSomething");
TTB_WAIT_SYNC();
TTB_EXP("CalculateSomething-Stop out_val=-99 return error (SimObjectA)");
TTB_EXP("CalculateSomething in_val=20 out_val=40 (SimObjectA)");
TTB_EXP("CalculateSomething in_val=21 out_val=42 (SimObjectA)");
t.join();
}