Skip to content

Commit

Permalink
chore: Unit test in github action (#24)
Browse files Browse the repository at this point in the history
* chore: Unit test in github action

* feat: Add optional req

* fix: Fix bug

---------

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored Jan 27, 2025
1 parent 846e74e commit 2da5a78
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches:
- main
paths:
- '.github/workflows/**'
- '**.py'
- 'setup.py'
pull_request:
paths:
- '.github/workflows/**'
- '**.py'
- 'setup.py'
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
python-tests:
name: Python Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r requirements-test.txt
- name: Run Tests
run: |
pytest
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
13 changes: 3 additions & 10 deletions src/tests/test_session_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from vllm_router.routing_logic import SessionRouter


class EndpointInfo:
def __init__(self, url: str):
self.url = url
Expand Down Expand Up @@ -117,8 +118,6 @@ def test_consistent_hashing_remove_node_multiple_sessions():
# Calculate the number of remapped session IDs
remapped_count = sum(1 for before, after in zip(
urls_before, urls_after) if before != after)
print(f"Remapped {remapped_count} out of {
len(session_ids)} session IDs after removing a node.")

# Ensure minimal reassignment
# Only a fraction should be remapped
Expand Down Expand Up @@ -163,13 +162,12 @@ def test_consistent_hashing_add_node_multiple_sessions():
# Calculate the number of remapped session IDs
remapped_count = sum(1 for before, after in zip(
urls_before, urls_after) if before != after)
print(f"Remapped {remapped_count} out of {
len(session_ids)} session IDs after adding a node.")

# Ensure minimal reassignment
# Only a fraction should be remapped
assert remapped_count < len(session_ids)


def test_consistent_hashing_add_then_remove_node():
"""
Test consistent hashing behavior when a node is added and then removed.
Expand Down Expand Up @@ -208,8 +206,6 @@ def test_consistent_hashing_add_then_remove_node():
# Calculate the number of remapped session IDs after adding
remapped_count_after_add = sum(1 for before, after in zip(
urls_before_add, urls_after_add) if before != after)
print(f"Remapped {remapped_count_after_add} out of {
len(session_ids)} session IDs after adding a node.")

# Ensure minimal reassignment after adding
assert remapped_count_after_add < len(session_ids)
Expand All @@ -229,14 +225,11 @@ def test_consistent_hashing_add_then_remove_node():
# Calculate the number of remapped session IDs after removing
remapped_count_after_remove = sum(1 for before, after in zip(
urls_after_add, urls_after_remove) if before != after)
print(f"Remapped {remapped_count_after_remove} out of {
len(session_ids)} session IDs after removing a node.")

# Ensure minimal reassignment after removing
assert remapped_count_after_remove < len(session_ids)

# Verify that session IDs mapped to unaffected nodes remain the same
unaffected_count = sum(1 for before, after in zip(
urls_before_add, urls_after_remove) if before == after)
print(f"{unaffected_count} out of {
len(session_ids)} session IDs were unaffected by adding and removing a node.")
print(f"{unaffected_count} out of {len(session_ids)} session IDs were unaffected by adding and removing a node.")

0 comments on commit 2da5a78

Please sign in to comment.