Add comprehensive unit tests for RadixCache with extra_key isolation following SGLang patterns#6
Conversation
Co-authored-by: JustinTong0323 <115166877+JustinTong0323@users.noreply.github.com>
Co-authored-by: JustinTong0323 <115166877+JustinTong0323@users.noreply.github.com>
|
@copilot follow other tests in sglang/test/run_suite.py, modify this test and add to the run_suite |
…e.py Co-authored-by: JustinTong0323 <115166877+JustinTong0323@users.noreply.github.com>
I've updated the radix cache unit test to follow SGLang testing patterns and added it to run_suite.py as requested. Key changes:
The test now integrates properly with SGLang's CI pipeline and follows the established patterns. Commit: 71ab977 |
| class TestNoSGLang(unittest.TestCase): | ||
| """Test case for when SGLang is not available.""" | ||
|
|
||
| @unittest.skipIf(HAS_SGLANG, "SGLang is available") | ||
| def test_graceful_fallback(self): | ||
| """Test that we gracefully handle missing SGLang.""" | ||
| self.assertTrue(True) # Just to have a passing test |
There was a problem hiding this comment.
remove this scenario, we are testing sglang, why we need this?
| except ImportError: | ||
| HAS_SGLANG = False | ||
| # Use regular unittest.TestCase if SGLang not available | ||
| CustomTestCase = unittest.TestCase |
|
@copilot address comments |
Co-authored-by: JustinTong0323 <115166877+JustinTong0323@users.noreply.github.com>
I've addressed both comments by removing the graceful fallback handling and TestNoSGLang class. The test now assumes SGLang and PyTorch dependencies are available since it's an internal SGLang test. Changes made:
The test is now streamlined for SGLang internal use without unnecessary fallback scenarios. Commit: 72ec5e9 |
|
@copilot review the radix cache, we need to ensure key with different extra_key should not match, but the test doesn't cover that. Also, review the source code of radix cache to improve the test coverage, but don't too messy |
Co-authored-by: JustinTong0323 <115166877+JustinTong0323@users.noreply.github.com>
I've reviewed the RadixCache source code and added comprehensive tests for extra_key isolation and improved overall coverage. Key additions:
The test suite now has 40 comprehensive tests (up from 31) covering all major RadixCache functionality without being messy. The extra_key isolation is thoroughly tested to ensure keys with different extra_key values are stored in separate tree branches and never match. Commit: 37b2789 |
…ache - Updated __getitem__ in BaseKey to return a BaseKey instance for single index access. - Added comprehensive tests for __len__, __iter__, and __getitem__ methods in BaseKey. - Improved RadixCache tests, including variations in initialization, insert and match operations, and event handling. - Enhanced coverage for edge cases and boundary conditions in tests. Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
|
@copilot review |
Code Review SummaryI've reviewed the current RadixCache unit test implementation and found both strengths and areas that needed fixing: ✅ Strengths:
📊 Current Status:
The test suite is now comprehensive, follows SGLang patterns correctly, and provides thorough validation of the RadixCache implementation. The recent regression has been fixed to ensure compliance with established testing patterns. |
This PR adds comprehensive unit tests for the RadixCache implementation, addressing a gap in the existing test coverage. While SGLang has integration tests for radix cache functionality, there were no focused unit tests for the core RadixCache, BaseKey, and TreeNode classes.
What's Added
The new test suite (
test/srt/test_radix_cache_unit.py) includes 30 individual tests covering:extra_keyvalues are properly isolated and cannot match each othertest/srt/run_suite.pyas part of the per-commit test suiteKey Features
CustomTestCaseand follows established SGLang testing patterns (followingtest_schedule_policy.pyandtest_swa_unittest.pypatterns)Example Usage
Testing Approach
The tests follow SGLang testing patterns by importing RadixCache components directly and using
CustomTestCaseas the base class. As an internal SGLang test, it assumes all dependencies are available, ensuring:This complements the existing integration tests by providing focused unit-level validation of the RadixCache implementation, which is a critical component of SGLang's KV cache management system.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.