| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from vllm.engine.arg_utils import EngineArgs |
| 7 | from vllm.sampling_params import SamplingParams |
| 8 | from vllm.v1.core.sched.scheduler import Scheduler |
| 9 | from vllm.v1.engine.llm_engine import LLMEngine |
| 10 | |
| 11 | |
| 12 | class DummyV1Scheduler(Scheduler): |
| 13 | def schedule(self, throttle_prefills: bool = False): |
| 14 | raise Exception("Exception raised by DummyV1Scheduler") |
| 15 | |
| 16 | |
| 17 | def test_scheduler_plugins_v1(monkeypatch: pytest.MonkeyPatch): |
| 18 | with monkeypatch.context() as m: |
| 19 | # Explicitly turn off engine multiprocessing so |
| 20 | # that the scheduler runs in this process |
| 21 | m.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0") |
| 22 | |
| 23 | with pytest.raises(Exception) as exception_info: |
| 24 | engine_args = EngineArgs( |
| 25 | model="facebook/opt-125m", |
| 26 | enforce_eager=True, # reduce test time |
| 27 | scheduler_cls=DummyV1Scheduler, |
| 28 | ) |
| 29 | |
| 30 | engine = LLMEngine.from_engine_args(engine_args=engine_args) |
| 31 | |
| 32 | sampling_params = SamplingParams(max_tokens=1) |
| 33 | engine.add_request("0", "foo", sampling_params) |
| 34 | engine.step() |
| 35 | |
| 36 | assert str(exception_info.value) == "Exception raised by DummyV1Scheduler" |