()
| 270 | |
| 271 | #[tokio::test] |
| 272 | async fn test_worker_pool_concurrency_limit() { |
| 273 | let pool = WorkerPool::new(2); |
| 274 | |
| 275 | // Submit 3 jobs that take 100ms each |
| 276 | let start = tokio::time::Instant::now(); |
| 277 | |
| 278 | let mut submitted = 0; |
| 279 | let mut attempts = 0; |
| 280 | while submitted < 3 && attempts < 100 { |
| 281 | let job = TestJob { |
| 282 | id: format!("job-{}", submitted), |
| 283 | duration_ms: 100, |
| 284 | should_fail: false, |
| 285 | }; |
| 286 | if pool.try_submit(job).await.unwrap().is_some() { |
| 287 | submitted += 1; |
| 288 | } else { |
| 289 | // Wait a bit for a worker to become available |
| 290 | sleep(Duration::from_millis(10)).await; |
| 291 | } |
| 292 | attempts += 1; |
| 293 | } |
| 294 | assert_eq!(submitted, 3, "Should have submitted all 3 jobs"); |
| 295 | |
| 296 | // Wait for all jobs to complete |
| 297 | sleep(Duration::from_millis(250)).await; |
| 298 | |
| 299 | // Poll for all completed jobs |
| 300 | let mut total_completed = 0; |
| 301 | loop { |
| 302 | let completed = pool.poll_completed().await; |
| 303 | total_completed += completed.len(); |
| 304 | if total_completed >= 3 { |
| 305 | break; |
| 306 | } |
| 307 | sleep(Duration::from_millis(10)).await; |
| 308 | } |
| 309 | |
| 310 | let elapsed = start.elapsed(); |
| 311 | |
| 312 | // With 2 workers and 3 jobs of 100ms each, it should take ~200ms |
| 313 | // (2 jobs run in parallel, then the 3rd runs) |
| 314 | assert_eq!(total_completed, 3, "All 3 jobs should complete"); |
| 315 | assert!( |
| 316 | elapsed >= Duration::from_millis(150), |
| 317 | "Should take at least 150ms" |
| 318 | ); |
| 319 | } |
| 320 | |
| 321 | #[tokio::test] |
| 322 | async fn test_worker_pool_error_handling() { |
nothing calls this directly
no test coverage detected