|
2 | 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
3 | 3 | # ruff: noqa |
4 | 4 |
|
5 | | -import asyncio |
6 | 5 | import hashlib |
7 | 6 | import json |
8 | 7 | import os |
9 | 8 | import pickle |
10 | 9 | import socket |
11 | 10 | import tempfile |
12 | | -from collections.abc import AsyncIterator |
13 | 11 | from pathlib import Path |
14 | 12 | from unittest.mock import patch |
15 | 13 |
|
|
37 | 35 | make_zmq_path, |
38 | 36 | make_zmq_socket, |
39 | 37 | memory_profiling, |
40 | | - merge_async_iterators, |
41 | 38 | sha256, |
42 | 39 | split_host_port, |
43 | 40 | split_zmq_path, |
|
48 | 45 | from ..utils import create_new_process_for_each_test |
49 | 46 |
|
50 | 47 |
|
51 | | -@pytest.mark.asyncio |
52 | | -async def test_merge_async_iterators(): |
53 | | - async def mock_async_iterator(idx: int): |
54 | | - try: |
55 | | - while True: |
56 | | - yield f"item from iterator {idx}" |
57 | | - await asyncio.sleep(0.1) |
58 | | - except asyncio.CancelledError: |
59 | | - print(f"iterator {idx} cancelled") |
60 | | - |
61 | | - iterators = [mock_async_iterator(i) for i in range(3)] |
62 | | - merged_iterator = merge_async_iterators(*iterators) |
63 | | - |
64 | | - async def stream_output(generator: AsyncIterator[tuple[int, str]]): |
65 | | - async for idx, output in generator: |
66 | | - print(f"idx: {idx}, output: {output}") |
67 | | - |
68 | | - task = asyncio.create_task(stream_output(merged_iterator)) |
69 | | - await asyncio.sleep(0.5) |
70 | | - task.cancel() |
71 | | - with pytest.raises(asyncio.CancelledError): |
72 | | - await task |
73 | | - |
74 | | - for iterator in iterators: |
75 | | - try: |
76 | | - await asyncio.wait_for(anext(iterator), 1) |
77 | | - except StopAsyncIteration: |
78 | | - # All iterators should be cancelled and print this message. |
79 | | - print("Iterator was cancelled normally") |
80 | | - except (Exception, asyncio.CancelledError) as e: |
81 | | - raise AssertionError() from e |
82 | | - |
83 | | - |
84 | 48 | def test_get_open_port(monkeypatch: pytest.MonkeyPatch): |
85 | 49 | with monkeypatch.context() as m: |
86 | 50 | m.setenv("VLLM_PORT", "5678") |
|
0 commit comments