Skip to content

Commit d20d5dc

Browse files
committed
Merge #18285: test: Check that wait_until returns if time point is in the past
fab7d14 test: Check that wait_until returns if time point is in the past (MarcoFalke) Pull request description: Add an explicit regression test for the condvar bug (#18227), so that this doesn't happen again ACKs for top commit: laanwj: ACK fab7d14 Tree-SHA512: 6ec0d0b3945cae87a001e367af34cca1953a8082b4a0d9f8a20d30acd1f36363e98035d4eb173ff786cf6692d352d41f960633415c46394af042eb44e3b5ad71
2 parents 414f6c4 + fab7d14 commit d20d5dc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/scheduler_tests.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ BOOST_AUTO_TEST_CASE(manythreads)
9898
BOOST_CHECK_EQUAL(counterSum, 200);
9999
}
100100

101+
BOOST_AUTO_TEST_CASE(wait_until_past)
102+
{
103+
std::condition_variable condvar;
104+
Mutex mtx;
105+
WAIT_LOCK(mtx, lock);
106+
107+
const auto no_wait= [&](const std::chrono::seconds& d) {
108+
return condvar.wait_until(lock, std::chrono::system_clock::now() - d);
109+
};
110+
111+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::seconds{1}));
112+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::minutes{1}));
113+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::hours{1}));
114+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::hours{10}));
115+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::hours{100}));
116+
BOOST_CHECK(std::cv_status::timeout == no_wait(std::chrono::hours{1000}));
117+
}
118+
101119
BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
102120
{
103121
CScheduler scheduler;

0 commit comments

Comments
 (0)