Unverified Commit 21b9a4b4 authored by Keyang Ru's avatar Keyang Ru Committed by GitHub
Browse files

[router] Introduce router integration tests (#10086)

parent db37422c
import collections
import subprocess
import time
import pytest
import requests
@pytest.mark.integration
def test_add_and_remove_worker(mock_worker, router_manager, mock_workers):
# Start with a single worker
proc1, url1, id1 = mock_worker
rh = router_manager.start_router(worker_urls=[url1], policy="round_robin")
# Add a second worker
procs2, urls2, ids2 = mock_workers(n=1)
url2 = urls2[0]
id2 = ids2[0]
router_manager.add_worker(rh.url, url2)
# Send some requests and ensure both workers are seen
seen = set()
with requests.Session() as s:
for i in range(20):
r = s.post(
f"{rh.url}/v1/completions",
json={
"model": "test-model",
"prompt": f"x{i}",
"max_tokens": 1,
"stream": False,
},
)
assert r.status_code == 200
wid = r.headers.get("X-Worker-Id") or r.json().get("worker_id")
seen.add(wid)
if len(seen) == 2:
break
assert id1 in seen and id2 in seen
# Now remove the second worker
router_manager.remove_worker(rh.url, url2)
# After removal, subsequent requests should only come from first worker
with requests.Session() as s:
for i in range(10):
r = s.post(
f"{rh.url}/v1/completions",
json={
"model": "test-model",
"prompt": f"y{i}",
"max_tokens": 1,
"stream": False,
},
)
assert r.status_code == 200
wid = r.headers.get("X-Worker-Id") or r.json().get("worker_id")
assert wid == id1
# mock_workers fixture handles cleanup
......@@ -14,6 +14,13 @@ if __name__ == "__main__":
args = arg_parser.parse_args()
files = glob.glob("**/test_*.py", recursive=True)
# Exclude integration tests from the e2e suite; those are run separately via pytest -m integration
files = [
f
for f in files
if "/integration/" not in f and not f.startswith("integration/")
]
files.sort()
test_files = [TestFile(name=file) for file in files]
exit_code = run_unittest_files(test_files, args.timeout_per_file)
......
......@@ -3,4 +3,3 @@ testpaths = py_test
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts = --cov=sglang_router --cov-report=term-missing
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment