@@ -1368,23 +1368,34 @@ TEST_F(AsyncIOTest, IntensiveAsyncOperations) {
13681368
13691369 // Create multiple threads performing async operations
13701370 for (int t = 0 ; t < 4 ; ++t) {
1371- threads.emplace_back ([&completed_operations]() {
1371+ threads.emplace_back ([&completed_operations, t ]() {
13721372 async::init ();
1373+
1374+ std::atomic<int > thread_completed{0 };
13731375
13741376 for (int i = 0 ; i < NUM_OPERATIONS; ++i) {
13751377 new async::Timeout<std::function<void ()>>(
1376- [&completed_operations]() { completed_operations++; }, 0.01 );
1378+ [&completed_operations, &thread_completed]() {
1379+ completed_operations++;
1380+ thread_completed++;
1381+ }, 0.01 );
13771382
1378- // Run event loop occasionally
1379- if (i % 1000 == 0 ) {
1383+ // Run event loop occasionally to prevent buildup
1384+ if (i % 100 == 0 ) {
13801385 async::run (EVRUN_NOWAIT);
13811386 }
13821387 }
13831388
1384- // Run event loop until all operations complete
1385- for (int i = 0 ; i < 50 && completed_operations < NUM_OPERATIONS; ++i) {
1389+ // Run event loop until ALL operations in this thread complete
1390+ for (int i = 0 ; i < 200 && thread_completed < NUM_OPERATIONS; ++i) {
13861391 async::run (EVRUN_ONCE);
1387- std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
1392+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
1393+ }
1394+
1395+ // Extra time to ensure all timers fire
1396+ for (int i = 0 ; i < 10 ; ++i) {
1397+ async::run (EVRUN_NOWAIT);
1398+ std::this_thread::sleep_for (std::chrono::milliseconds (20 ));
13881399 }
13891400 });
13901401 }
0 commit comments