(self, mock_gather, mock_get_request)
| 137 | @patch("fastdeploy.benchmarks.serve.get_request") |
| 138 | @patch("asyncio.gather", new_callable=AsyncMock) |
| 139 | async def test_benchmark(self, mock_gather, mock_get_request): |
| 140 | # 直接在测试中设置ASYNC_REQUEST_FUNCS |
| 141 | from fastdeploy.benchmarks.serve import ASYNC_REQUEST_FUNCS |
| 142 | |
| 143 | mock_func = AsyncMock() |
| 144 | ASYNC_REQUEST_FUNCS["test_backend"] = mock_func |
| 145 | from fastdeploy.benchmarks.datasets import SampleRequest |
| 146 | |
| 147 | # 创建一个异步生成器函数来模拟get_request |
| 148 | async def mock_request_gen(): |
| 149 | yield SampleRequest( |
| 150 | no=1, prompt="test", prompt_len=10, expected_output_len=20, history_QA=[], json_data=None |
| 151 | ) |
| 152 | |
| 153 | mock_get_request.return_value = mock_request_gen() |
| 154 | mock_func.return_value = MagicMock( |
| 155 | success=True, |
| 156 | prompt_len=10, |
| 157 | prompt_tokens=10, |
| 158 | output_tokens=20, |
| 159 | ttft=0.1, |
| 160 | itl=[0.02, 0.02, 0.02], |
| 161 | latency=0.5, |
| 162 | arrival_time=[0, 0.1, 0.12, 0.14, 0.16], |
| 163 | generated_text="test output", |
| 164 | reasoning_content=None, |
| 165 | error=None, |
| 166 | ) |
| 167 | |
| 168 | result = await benchmark( |
| 169 | backend="test_backend", |
| 170 | api_url="http://test", |
| 171 | base_url="http://test", |
| 172 | model_id="test_model", |
| 173 | model_name="test_model", |
| 174 | input_requests=[ |
| 175 | SampleRequest( |
| 176 | no=1, prompt="test", prompt_len=10, expected_output_len=20, history_QA=[], json_data=None |
| 177 | ) |
| 178 | ], |
| 179 | hyper_parameters={}, |
| 180 | logprobs=None, |
| 181 | request_rate=1.0, |
| 182 | burstiness=1.0, |
| 183 | disable_tqdm=True, |
| 184 | profile=False, |
| 185 | selected_percentile_metrics=["ttft", "tpot", "itl"], |
| 186 | selected_percentiles=[99], |
| 187 | ignore_eos=False, |
| 188 | debug=False, |
| 189 | goodput_config_dict={}, |
| 190 | max_concurrency=None, |
| 191 | lora_modules=None, |
| 192 | extra_body=None, |
| 193 | ) |
| 194 | self.assertEqual(result["total_input_tokens"], 0) |
| 195 | |
| 196 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected