Poll a condition with sleep between attempts. Loopback TCP is fast but accept/recv may not be ready immediately, especially under heavy load.
| 75 | // Poll a condition with sleep between attempts. Loopback TCP is fast but |
| 76 | // accept/recv may not be ready immediately, especially under heavy load. |
| 77 | static bool pollUntil(fl::function<bool()> pred, int maxAttempts = 100) { |
| 78 | for (int i = 0; i < maxAttempts; ++i) { |
| 79 | if (pred()) return true; |
| 80 | fl::this_thread::sleep_for(fl::chrono::milliseconds(10)); // ok sleep for |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | // ============================================================================= |
| 86 | // Pure state-machine tests (no TCP connections needed) |
no test coverage detected