@@ -13,14 +13,21 @@ using namespace fastmcpp;
1313using namespace fastmcpp ::tools;
1414using namespace std ::chrono_literals;
1515
16+ static void sleep_for_at_least (std::chrono::milliseconds duration)
17+ {
18+ auto deadline = std::chrono::steady_clock::now () + duration;
19+ while (std::chrono::steady_clock::now () < deadline)
20+ std::this_thread::sleep_for (1ms);
21+ }
22+
1623void test_tool_timeout_triggers ()
1724{
1825 std::cout << " test_tool_timeout_triggers... " << std::flush;
1926
2027 Tool slow_tool (" slow" , Json::object (), Json::object (),
2128 [](const Json&) -> Json
2229 {
23- std::this_thread::sleep_for (50ms);
30+ sleep_for_at_least (50ms);
2431 return Json{{" ok" , true }};
2532 });
2633
@@ -47,7 +54,7 @@ void test_tool_timeout_disabled()
4754 Tool slow_tool (" slow_no_timeout" , Json::object (), Json::object (),
4855 [](const Json&) -> Json
4956 {
50- std::this_thread::sleep_for (30ms);
57+ sleep_for_at_least (30ms);
5158 return Json{{" ok" , true }};
5259 });
5360
@@ -65,7 +72,7 @@ void test_manager_timeout_toggle()
6572 Tool slow_tool (" slow_manager" , Json::object (), Json::object (),
6673 [](const Json&) -> Json
6774 {
68- std::this_thread::sleep_for (40ms);
75+ sleep_for_at_least (40ms);
6976 return Json{{" ok" , true }};
7077 });
7178
0 commit comments