Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
21b9a4b4
Unverified
Commit
21b9a4b4
authored
Sep 05, 2025
by
Keyang Ru
Committed by
GitHub
Sep 05, 2025
Browse files
[router] Introduce router integration tests (#10086)
parent
db37422c
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
1 deletion
+68
-1
sgl-router/py_test/integration/test_worker_management.py
sgl-router/py_test/integration/test_worker_management.py
+61
-0
sgl-router/py_test/run_suite.py
sgl-router/py_test/run_suite.py
+7
-0
sgl-router/pytest.ini
sgl-router/pytest.ini
+0
-1
No files found.
sgl-router/py_test/integration/test_worker_management.py
0 → 100644
View file @
21b9a4b4
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
sgl-router/py_test/run_suite.py
View file @
21b9a4b4
...
...
@@ -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
)
...
...
sgl-router/pytest.ini
View file @
21b9a4b4
...
...
@@ -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
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment