()
| 1027 | |
| 1028 | #[tokio::test] |
| 1029 | async fn test_worker_pool_count_tracking() { |
| 1030 | // Test that the worker pool properly tracks active and available workers |
| 1031 | use crate::server::worker_pool::{AsyncJob, JobError, JobResult, WorkerPool}; |
| 1032 | |
| 1033 | // Simple test job for worker pool testing |
| 1034 | struct SimpleJob { |
| 1035 | id: String, |
| 1036 | should_succeed: bool, |
| 1037 | } |
| 1038 | |
| 1039 | impl AsyncJob for SimpleJob { |
| 1040 | async fn execute(self) -> Result<JobResult, JobError> { |
| 1041 | sleep(Duration::from_millis(10)).await; |
| 1042 | if self.should_succeed { |
| 1043 | Ok(JobResult { |
| 1044 | job_id: self.id, |
| 1045 | success: true, |
| 1046 | message: Some("Success".to_string()), |
| 1047 | }) |
| 1048 | } else { |
| 1049 | Ok(JobResult { |
| 1050 | job_id: self.id, |
| 1051 | success: false, |
| 1052 | message: Some("Failed".to_string()), |
| 1053 | }) |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | fn job_id(&self) -> String { |
| 1058 | self.id.clone() |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | // Create a worker pool with 3 workers |
| 1063 | let pool = WorkerPool::new(3); |
| 1064 | |
| 1065 | // Initially all workers should be available |
| 1066 | assert_eq!(pool.total_workers(), 3); |
| 1067 | assert_eq!(pool.available_workers(), 3); |
| 1068 | assert_eq!(pool.active_workers(), 0); |
| 1069 | |
| 1070 | // Submit 2 jobs |
| 1071 | let job1 = SimpleJob { |
| 1072 | id: "job-1".to_string(), |
| 1073 | should_succeed: true, |
| 1074 | }; |
| 1075 | let job2 = SimpleJob { |
| 1076 | id: "job-2".to_string(), |
| 1077 | should_succeed: false, |
| 1078 | }; |
| 1079 | |
| 1080 | pool.try_submit(job1).await.unwrap().unwrap(); |
| 1081 | pool.try_submit(job2).await.unwrap().unwrap(); |
| 1082 | |
| 1083 | // Give jobs a moment to start |
| 1084 | sleep(Duration::from_millis(5)).await; |
| 1085 | |
| 1086 | // Check counts with 2 active jobs |
nothing calls this directly
no test coverage detected