Skip to content

Conversation

@xunyoyo
Copy link

@xunyoyo xunyoyo commented Nov 15, 2025

This file contains tests for the global scheduler, including request handling, load accounting, and response management.

Motivation

NO.38 功能模块 fastdeploy/scheduler/global_scheduler.py 单测补充

Modifications

new dir and add tests/scheduler/test_global_scheduler.py

Usage or Command

tests/scheduler/test_global_scheduler.py:

python -m coverage run -m unittest tests.scheduler.test_global_scheduler \
&& python -m coverage report -m --include='fastdeploy/scheduler/global_scheduler.py'

Accuracy Tests

tests/scheduler/test_global_scheduler.py:

Name                                       Stmts   Miss  Cover   Missing
------------------------------------------------------------------------
fastdeploy/scheduler/global_scheduler.py     369     62    83%   200-202, 214-215, 231-241, 332, 424-429, 440-441, 499-502, 511,
 520, 532-533, 542-543, 556-561, 576, 601, 652, 681-682, 699-730, 774-775
------------------------------------------------------------------------
TOTAL                                        369     62    83%

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.

This file contains tests for the global scheduler, including request handling, load accounting, and response management.
Copilot AI review requested due to automatic review settings November 15, 2025 10:40
@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:43
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 global scheduler module (fastdeploy/scheduler/global_scheduler.py) as part of Hackathon 9th Sprint No.38. The tests use pytest with custom fixtures and mocks to achieve 83% code coverage.

Key Changes

  • Implements fake Redis and worker implementations for isolated testing
  • Tests request handling, load balancing, request stealing, and response routing
  • Adds tests for scheduler configuration and reset functionality
  • Includes helper function tests for block calculation and request/response marking


def test_get_requests_requeues_when_chunked_limits_hit(scheduler_fixture):
scheduler, fake_redis = scheduler_fixture
envs.FD_ENABLE_MAX_PREFILL = 0
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.

Directly modifying envs.FD_ENABLE_MAX_PREFILL without restoring it can lead to test isolation issues. Consider using monkeypatch.setattr(envs, "FD_ENABLE_MAX_PREFILL", 0) to ensure the value is automatically restored after the test completes.

Copilot uses AI. Check for mistakes.

def test_get_requests_blocking_pop_returns_when_idle(scheduler_fixture):
scheduler, fake_redis = scheduler_fixture
envs.FD_ENABLE_MAX_PREFILL = 0
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.

Directly modifying envs.FD_ENABLE_MAX_PREFILL without restoring it can lead to test isolation issues. Consider using monkeypatch.setattr(envs, "FD_ENABLE_MAX_PREFILL", 0) to ensure the value is automatically restored after the test completes.

Copilot uses AI. Check for mistakes.
bucket = self.lists.get(key)
if not bucket:
return None
if count is None or count <= 1:
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.

Inconsistent return behavior in lpop: when count is None or count <= 1, it returns a list with one element [bucket.pop(0)], but the check if count is None or count <= 1 treats count=0 the same as count=1. When count=0, the method should return an empty list [] or None, not a list with one element. This could cause the fake Redis to behave differently than the real Redis implementation.

Suggested change
if count is None or count <= 1:
if count == 0:
return []
if count is None or count == 1:

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +97
removed += int(key in self.kv or key in self.lists)
self.kv.pop(key, None)
self.lists.pop(key, None)
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.

The delete method doesn't handle keys in sorted_sets. If a key exists in sorted_sets but not in kv or lists, it won't be counted as removed or actually deleted. This could cause the fake Redis to behave incorrectly when testing deletion of sorted set keys.

Suggested change
removed += int(key in self.kv or key in self.lists)
self.kv.pop(key, None)
self.lists.pop(key, None)
removed += int(key in self.kv or key in self.lists or key in self.sorted_sets)
self.kv.pop(key, None)
self.lists.pop(key, None)
self.sorted_sets.pop(key, None)

Copilot uses AI. Check for mistakes.
return removed

def exists(self, key: str) -> int:
if key in self.kv or key in self.lists:
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.

The exists method doesn't check sorted_sets, only kv and lists. If a key exists in sorted_sets, this method will incorrectly return 0, indicating the key doesn't exist.

Suggested change
if key in self.kv or key in self.lists:
if key in self.kv or key in self.lists or key in self.sorted_sets:

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6
python -m coverage run -m pytest tests/scheduler/test_global_scheduler.py \
&& python -m coverage report -m --include='fastdeploy/scheduler/global_scheduler.py'
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.

The command in the docstring uses pytest (python -m coverage run -m pytest), but the PR description specifies unittest (python -m unittest tests.scheduler.test_global_scheduler). These should be consistent. Since the tests use pytest fixtures, the docstring appears correct, but this inconsistency with the PR description may confuse users.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,431 @@
"""Tests for the global scheduler.
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 the Apache 2.0 license header that is present in all other test files in this repository. The copyright header should be added at the top of the file following the project's convention:

"""
# Copyright (c) 2025  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""

Copilot uses AI. Check for mistakes.

def test_get_requests_can_steal_remote_request(monkeypatch, scheduler_fixture):
scheduler, fake_redis = scheduler_fixture
envs.FD_ENABLE_MAX_PREFILL = 0
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.

Directly modifying envs.FD_ENABLE_MAX_PREFILL without restoring it can lead to test isolation issues. Consider using monkeypatch.setattr(envs, "FD_ENABLE_MAX_PREFILL", 0) to ensure the value is automatically restored after the test completes.

Suggested change
envs.FD_ENABLE_MAX_PREFILL = 0
monkeypatch.setattr(envs, "FD_ENABLE_MAX_PREFILL", 0)

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