Skip to content

Conversation

@xunyoyo
Copy link

@xunyoyo xunyoyo commented Nov 15, 2025

Motivation

NO.36 功能模块 fastdeploy/cache_manager/prefix_cache_manager.py 单测补充

Modifications

new tests/cache_manager/prefix_cache_manager.py

Usage or Command

tests/cache_manager/prefix_cache_manager.py:

python -m coverage run -m unittest tests.cache_manager.test_prefix_cache_manager \
&& python -m coverage report -m --include='fastdeploy/cache_manager/cache_manager.py'

Accuracy Tests

tests/cache_manager/prefix_cache_manager.py:

Name                                               Stmts   Miss  Cover   Missing
--------------------------------------------------------------------------------
fastdeploy/cache_manager/prefix_cache_manager.py     893    175    80%   359, 372-390, 400, 457-458, 493, 526-537, 591, 602-623,
 630, 635, 667, 703, 724, 735-737, 834, 840-842, 848, 851-853, 875, 880-882, 885, 894-896, 916, 926, 929-931, 941, 982, 1025-102
9, 1045, 1061, 1068-1071, 1076, 1089, 1096-1097, 1103-1106, 1119-1121, 1139, 1146-1168, 1220, 1228, 1271-1272, 1280-1289, 1294-1
300, 1325, 1348, 1361-1363, 1365-1367, 1373-1379, 1391, 1393, 1399, 1461, 1472-1474, 1480-1486, 1495, 1500, 1541, 1547, 1562, 15
94, 1597, 1634-1637, 1647, 1671, 1674, 1676, 1687, 1709-1711, 1727, 1766-1767, 1775, 1807
--------------------------------------------------------------------------------
TOTAL                                                893    175    80%

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

Copilot AI review requested due to automatic review settings November 15, 2025 10:33
@paddle-bot
Copy link

paddle-bot bot commented Nov 15, 2025

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Nov 15, 2025
Copilot finished reviewing on behalf of xunyoyo November 15, 2025 10:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive unit tests for the fastdeploy/cache_manager/prefix_cache_manager.py module, achieving 80% code coverage as part of Hackathon 9th Sprint No.36. The tests cover various aspects of the PrefixCacheManager including block allocation/recycling, cache matching, multimodal input handling, swap operations, and process lifecycle management.

Key Changes

  • Added 931 lines of test code with 27 test methods covering core functionality
  • Implemented extensive mock infrastructure to enable testing without actual dependencies (paddle, paddleformers)
  • Achieved 80% coverage of the prefix_cache_manager module with comprehensive test scenarios

Comment on lines +118 to +124
class _PollingProcess(_DummyProcess):
def __init__(self, *args, poll_value=None, **kwargs):
super().__init__(*args, **kwargs)
self._poll_value = poll_value

def poll(self):
return self._poll_value
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for _PollingProcess class. Consider adding a brief description explaining it extends _DummyProcess to return a configurable poll value.

Copilot uses AI. Check for mistakes.
Comment on lines +127 to +133
class _DummyThread:
def __init__(self, target=None, **kwargs):
self.target = target
self.started = False

def start(self):
self.started = True
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for _DummyThread class. Consider adding a brief description of its purpose as a test stub for threading.Thread.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +144
class _ImmediateFuture:
def __init__(self, fn=None, *args):
self._result = fn(*args) if fn is not None else None

def result(self):
return self._result

def done(self):
return True
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for _ImmediateFuture class. Consider adding a brief description explaining it mimics a Future object that completes immediately.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +16
class _StubLogger:
def __init__(self):
self.logger = self

def setLevel(self, *_):
pass
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for _StubLogger class. Consider adding a brief description explaining it provides a minimal logger stub for testing purposes.

Copilot uses AI. Check for mistakes.
return self.metrics[name]


class _DummyIPCSignal:
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring for _DummyIPCSignal class. Consider adding a brief description of its purpose as a test stub for IPC signals.

Suggested change
class _DummyIPCSignal:
class _DummyIPCSignal:
"""Test stub for IPC signals used in unit tests."""

Copilot uses AI. Check for mistakes.
),
patch(
"fastdeploy.cache_manager.prefix_cache_manager.subprocess.Popen",
lambda *args, **kwargs: _DummyProcess(*args, **kwargs),
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Copilot uses AI. Check for mistakes.
),
patch(
"fastdeploy.cache_manager.prefix_cache_manager.subprocess.Popen",
lambda *args, **kwargs: _DummyProcess(*args, **kwargs),
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Copilot uses AI. Check for mistakes.
),
patch(
"fastdeploy.cache_manager.prefix_cache_manager.subprocess.Popen",
lambda *args, **kwargs: _DummyProcess(*args, **kwargs),
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Suggested change
lambda *args, **kwargs: _DummyProcess(*args, **kwargs),
_DummyProcess,

Copilot uses AI. Check for mistakes.
Comment on lines +662 to +663
manager.free_cpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Suggested change
manager.free_cpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
manager.free_cpu_executor_pool = types.SimpleNamespace(submit=_ImmediateFuture)
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=_ImmediateFuture)

Copilot uses AI. Check for mistakes.
manager.cache_config.enable_hierarchical_cache = True
manager.cache_task_queue = _DummyEngineCacheQueue()
manager.free_cpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Suggested change
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=lambda fn, *args: _ImmediateFuture(fn, *args))
manager.free_gpu_executor_pool = types.SimpleNamespace(submit=_ImmediateFuture)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants