write-sglang-test
Installation
SKILL.md
Writing SGLang CI / UT Tests
Apply kernel-organization for the public operator namespace, logical grouping, lazy registry metadata, and test placement. The implementation tutorial below does not replace that API contract.
This skill covers how to write and register tests. For CI pipeline internals (stage ordering, fail-fast, gating, partitioning, debugging CI failures), see the CI workflow guide. Whether a case is worth adding at all is decided by unit-test-admission — read it before writing the case, not after.
Core Rules
- Always use
CustomTestCase— never rawunittest.TestCase. It ensurestearDownClassruns even whensetUpClassfails, preventing resource leaks in CI. tearDownClassmust shut the server down gracefully — callterminate_and_kill_process_tree(cls.process), never a barekill_process_tree. SIGKILL alone skips the server's userspace cleanup and leaves its GPU memory charged to the dead process; the next class then OOMs while loading weights. Keep it defensive too:hasattr/null checks before accessing resources (e.g.cls.process) thatsetUpClassmay not have finished allocating.- Place non-kernel tests in
test/registered/<kind>/<subsystem>/—<kind>isunit,e2e,accuracy,perf, orstress; kernel tests usetest/registered/kernels/{ops,benchmark}/<group>/; hardware belongs in registrations, not directory names - Reuse server fixtures — inherit from
DefaultServerBaseor writesetUpClass/tearDownClasswithpopen_launch_server - Mock boundaries, not SGLang behavior — mock slow or external dependencies only when the assertion still checks an observable result, state transition, or error. A test whose evidence is only
assert_called*mirrors its mock and is not admissible. Launch a real server only when inference results or lifecycle behavior are the contract under test.