Skip to content

Commit ab0e455

Browse files
committed
better polling wait
1 parent 84d06c1 commit ab0e455

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/test/fixtures.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,23 @@ bool connected_test::database_exists(std::string const & name)
4646

4747
void connected_test::wait_for(std::function<bool()> predicate, unsigned retries)
4848
{
49+
// Use exponential backoff: start with short waits, increase gradually
50+
// This is more efficient for slow systems (especially Windows async operations)
51+
unsigned wait_ms = milliseconds_waiting_time;
52+
const unsigned max_wait_ms = 500; // Cap at 500ms
53+
4954
for (unsigned i = 0; i < retries; i++) {
5055
if (predicate()) {
5156
return;
5257
}
5358

54-
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds_waiting_time));
59+
std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms));
60+
61+
// Exponential backoff: increase wait time gradually, cap at max_wait_ms
62+
wait_ms += milliseconds_waiting_time;
63+
if (wait_ms > max_wait_ms) {
64+
wait_ms = max_wait_ms;
65+
}
5566
}
5667
}
5768

src/test/simple_api_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ SCENARIO_METHOD(simple_connected_test, "more than 1000 inserts per second") {
197197

198198

199199
AND_THEN("All entries arrive at the database") {
200-
// wait for asynchronous fill
200+
// wait for asynchronous fill - Windows needs more time for async batching
201201
auto query = std::string("select count(*) from ") + db_name + "..asynctest";
202-
wait_for([this, query, many_times] { return raw_db.get(query).find(std::to_string(many_times.count)) != std::string::npos; }, 200);
202+
// Use more retries for slower systems (400 retries * 100ms = 40 seconds max)
203+
wait_for([this, query, many_times] { return raw_db.get(query).find(std::to_string(many_times.count)) != std::string::npos; }, 400);
203204
bool all_entries_arrived = raw_db.get(query).find(std::to_string(many_times.count)) != std::string::npos;
204205

205206
CHECK(all_entries_arrived);

0 commit comments

Comments
 (0)