()
| 227 | |
| 228 | #[tokio::test] |
| 229 | async fn test_worker_pool_concurrent_execution() { |
| 230 | let pool = WorkerPool::new(2); |
| 231 | |
| 232 | // Submit 4 jobs to a pool with 2 workers |
| 233 | let mut submitted = 0; |
| 234 | let mut attempts = 0; |
| 235 | while submitted < 4 && attempts < 100 { |
| 236 | let job = TestJob { |
| 237 | id: format!("job-{}", submitted), |
| 238 | duration_ms: 50, |
| 239 | should_fail: false, |
| 240 | }; |
| 241 | if pool.try_submit(job).await.unwrap().is_some() { |
| 242 | submitted += 1; |
| 243 | } else { |
| 244 | // Wait a bit for a worker to become available |
| 245 | sleep(Duration::from_millis(10)).await; |
| 246 | } |
| 247 | attempts += 1; |
| 248 | } |
| 249 | assert_eq!(submitted, 4, "Should have submitted all 4 jobs"); |
| 250 | |
| 251 | // Wait for all jobs to complete |
| 252 | sleep(Duration::from_millis(150)).await; |
| 253 | |
| 254 | // Poll for completed jobs |
| 255 | let mut all_completed = Vec::new(); |
| 256 | loop { |
| 257 | let completed = pool.poll_completed().await; |
| 258 | if completed.is_empty() { |
| 259 | break; |
| 260 | } |
| 261 | all_completed.extend(completed); |
| 262 | } |
| 263 | |
| 264 | assert_eq!(all_completed.len(), 4, "All 4 jobs should complete"); |
| 265 | for result in &all_completed { |
| 266 | assert!(result.is_ok()); |
| 267 | assert!(result.as_ref().unwrap().success); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | #[tokio::test] |
| 272 | async fn test_worker_pool_concurrency_limit() { |
nothing calls this directly
no test coverage detected