()
| 438 | |
| 439 | #[tokio::test] |
| 440 | async fn test_worker_pool_worker_counts() { |
| 441 | let pool = WorkerPool::new(3); |
| 442 | |
| 443 | // Initially all workers should be available |
| 444 | assert_eq!(pool.total_workers(), 3); |
| 445 | assert_eq!(pool.available_workers(), 3); |
| 446 | assert_eq!(pool.active_workers(), 0); |
| 447 | |
| 448 | // Submit a job |
| 449 | let job1 = TestJob { |
| 450 | id: "job-1".to_string(), |
| 451 | duration_ms: 100, |
| 452 | should_fail: false, |
| 453 | }; |
| 454 | pool.try_submit(job1).await.unwrap().unwrap(); |
| 455 | |
| 456 | // One worker should be busy |
| 457 | sleep(Duration::from_millis(10)).await; // Give it a moment to start |
| 458 | assert_eq!(pool.total_workers(), 3); |
| 459 | assert_eq!(pool.available_workers(), 2); |
| 460 | assert_eq!(pool.active_workers(), 1); |
| 461 | |
| 462 | // Submit another job |
| 463 | let job2 = TestJob { |
| 464 | id: "job-2".to_string(), |
| 465 | duration_ms: 100, |
| 466 | should_fail: false, |
| 467 | }; |
| 468 | pool.try_submit(job2).await.unwrap().unwrap(); |
| 469 | |
| 470 | // Two workers should be busy |
| 471 | sleep(Duration::from_millis(10)).await; |
| 472 | assert_eq!(pool.total_workers(), 3); |
| 473 | assert_eq!(pool.available_workers(), 1); |
| 474 | assert_eq!(pool.active_workers(), 2); |
| 475 | |
| 476 | // Wait for jobs to complete |
| 477 | sleep(Duration::from_millis(120)).await; |
| 478 | |
| 479 | // Poll to clean up completed jobs |
| 480 | let _ = pool.poll_completed().await; |
| 481 | |
| 482 | // All workers should be available again |
| 483 | assert_eq!(pool.total_workers(), 3); |
| 484 | assert_eq!(pool.available_workers(), 3); |
| 485 | assert_eq!(pool.active_workers(), 0); |
| 486 | } |
| 487 | } |
nothing calls this directly
no test coverage detected