@@ -556,23 +556,31 @@ namespace bq {
556556 thread1.join ();
557557 }
558558 {
559+ #ifdef BQ_IN_GITHUB_ACTIONS
560+ constexpr uint64_t precision_ms = 2000 ; // Github runners have very bad timer precision
561+ #else
562+ constexpr uint64_t precision_ms = 500 ;
563+ #endif
564+ constexpr uint64_t sleep_time_ms = 5000 ;
565+ constexpr uint64_t min_sleep_time_ms = sleep_time_ms - precision_ms;
566+ constexpr uint64_t max_sleep_time_ms = sleep_time_ms + precision_ms;
559567 for (int32_t i = 0 ; i < 5 ; ++i) {
560568 auto start_time = bq::platform::high_performance_epoch_ms ();
561569 bq::platform::mutex condition_timeout_mutex_;
562570 bq::platform::condition_variable condition_timeout_variable_;
563571 condition_timeout_mutex_.lock ();
564- condition_timeout_variable_.wait_for (condition_timeout_mutex_, 5000 );
572+ condition_timeout_variable_.wait_for (condition_timeout_mutex_, sleep_time_ms );
565573 condition_timeout_mutex_.unlock ();
566574 auto end_time = bq::platform::high_performance_epoch_ms ();
567575 auto diff = end_time - start_time;
568- result.add_result (diff > 4000 && diff < 6000 , " condition variable timeout test, real time elapsed:%" PRIu64 " ms, expect (4000, 6000 )ms" , diff);
576+ result.add_result (diff > min_sleep_time_ms && diff < max_sleep_time_ms , " condition variable timeout test, real time elapsed:%" PRIu64 " ms, expect (% " PRIu64 " , % " PRIu64 " )ms" , diff, max_sleep_time_ms, min_sleep_time_ms );
569577 }
570578 for (int32_t i = 0 ; i < 5 ; ++i) {
571579 auto start_time = bq::platform::high_performance_epoch_ms ();
572- bq::platform::thread::sleep (5000 );
580+ bq::platform::thread::sleep (sleep_time_ms );
573581 auto end_time = bq::platform::high_performance_epoch_ms ();
574582 auto diff = end_time - start_time;
575- result.add_result (diff > 4000 && diff < 6000 , " sleep test, real time elapsed:%" PRIu64 " ms, expect (4000, 6000 )ms" , diff);
583+ result.add_result (diff > min_sleep_time_ms && diff < max_sleep_time_ms , " sleep test, real time elapsed:%" PRIu64 " ms, expect (% " PRIu64 " , % " PRIu64 " )ms" , diff, max_sleep_time_ms, min_sleep_time_ms );
576584 }
577585 }
578586
0 commit comments