Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 57ed629

Browse files
authored
chore: add download success e2e test (#1556)
* chore: add download success e2e test * update
1 parent 42d416a commit 57ed629

File tree

4 files changed

+58
-19
lines changed

4 files changed

+58
-19
lines changed

.github/workflows/cortex-cpp-quality-gate.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ name: CI Quality Gate Cortex CPP
33
on:
44
pull_request:
55
types: [opened, synchronize, reopened, ready_for_review]
6-
paths:
7-
[
8-
"engine/**",
9-
".github/workflows/cortex-cpp-quality-gate.yml"
10-
]
6+
paths: ["engine/**", ".github/workflows/cortex-cpp-quality-gate.yml"]
117
workflow_dispatch:
128

139
env:
@@ -27,25 +23,25 @@ jobs:
2723
runs-on: "ubuntu-20-04-cuda-12-0"
2824
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
2925
build-deps-cmake-flags: ""
30-
ccache-dir: ''
26+
ccache-dir: ""
3127
- os: "mac"
3228
name: "amd64"
3329
runs-on: "macos-selfhosted-12"
3430
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
3531
build-deps-cmake-flags: ""
36-
ccache-dir: ''
32+
ccache-dir: ""
3733
- os: "mac"
3834
name: "arm64"
3935
runs-on: "macos-silicon"
4036
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DMAC_ARM64=ON -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
4137
build-deps-cmake-flags: ""
42-
ccache-dir: ''
38+
ccache-dir: ""
4339
- os: "windows"
4440
name: "amd64"
4541
runs-on: "windows-cuda-12-0"
4642
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DCMAKE_BUILD_TEST=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=C:/w/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
4743
build-deps-cmake-flags: "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
48-
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
44+
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
4945
steps:
5046
- name: Clone
5147
id: checkout
@@ -56,7 +52,7 @@ jobs:
5652
- name: use python
5753
uses: actions/setup-python@v5
5854
with:
59-
python-version: '3.10'
55+
python-version: "3.10"
6056

6157
- name: Install tools on Linux
6258
if: runner.os == 'Linux'
@@ -128,8 +124,7 @@ jobs:
128124
cp build/cortex build/cortex-nightly
129125
cp build/cortex build/cortex-beta
130126
python -m pip install --upgrade pip
131-
python -m pip install pytest
132-
python -m pip install requests
127+
python -m pip install -r e2e-test/requirements.txt
133128
python e2e-test/main.py
134129
rm build/cortex-nightly
135130
rm build/cortex-beta
@@ -143,8 +138,7 @@ jobs:
143138
cp build/cortex.exe build/cortex-nightly.exe
144139
cp build/cortex.exe build/cortex-beta.exe
145140
python -m pip install --upgrade pip
146-
python -m pip install pytest
147-
python -m pip install requests
141+
python -m pip install -r e2e-test/requirements.txt
148142
python e2e-test/main.py
149143
rm build/cortex-nightly.exe
150144
rm build/cortex-beta.exe
@@ -155,7 +149,7 @@ jobs:
155149
run: |
156150
cd engine
157151
make pre-package DESTINATION_BINARY_NAME="cortex"
158-
152+
159153
- name: Package
160154
run: |
161155
cd engine
@@ -188,4 +182,4 @@ jobs:
188182
env:
189183
AWS_ACCESS_KEY_ID: "${{ secrets.MINIO_ACCESS_KEY_ID }}"
190184
AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}"
191-
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"
185+
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"

engine/e2e-test/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
websockets
2+
pytest
3+
pytest-asyncio
4+
requests

engine/e2e-test/test_api_model_pull_direct_url.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import pytest
22
import requests
3-
from test_runner import start_server, stop_server, run
3+
from test_runner import (
4+
run,
5+
start_server,
6+
stop_server,
7+
wait_for_websocket_download_success_event,
8+
)
49

510

611
class TestApiModelPullDirectUrl:
@@ -30,11 +35,21 @@ def setup_and_teardown(self):
3035
"TheBloke:TinyLlama-1.1B-Chat-v0.3-GGUF:tinyllama-1.1b-chat-v0.3.Q2_K.gguf",
3136
],
3237
)
33-
stop_server()
38+
stop_server()
3439

35-
def test_model_pull_with_direct_url_should_be_success(self):
40+
@pytest.mark.asyncio
41+
async def test_model_pull_with_direct_url_should_be_success(self):
3642
myobj = {
3743
"model": "https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/blob/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf"
3844
}
3945
response = requests.post("http://localhost:3928/models/pull", json=myobj)
4046
assert response.status_code == 200
47+
await wait_for_websocket_download_success_event(timeout=None)
48+
get_model_response = requests.get(
49+
"http://127.0.0.1:3928/models/TheBloke:TinyLlama-1.1B-Chat-v0.3-GGUF:tinyllama-1.1b-chat-v0.3.Q2_K.gguf"
50+
)
51+
assert get_model_response.status_code == 200
52+
assert (
53+
get_model_response.json()["model"]
54+
== "TheBloke:TinyLlama-1.1B-Chat-v0.3-GGUF:tinyllama-1.1b-chat-v0.3.Q2_K.gguf"
55+
)

engine/e2e-test/test_runner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
import json
13
import platform
24
import queue
35
import select
@@ -6,6 +8,8 @@
68
import time
79
from typing import List
810

11+
import websockets
12+
913
# You might want to change the path of the executable based on your build directory
1014
executable_windows_path = "build\\cortex.exe"
1115
executable_unix_path = "build/cortex"
@@ -161,3 +165,25 @@ def enqueue_output(out, queue):
161165
# Stop the API server
162166
def stop_server():
163167
run("Stop server", ["stop"])
168+
169+
170+
async def wait_for_websocket_download_success_event(timeout: float = 30):
171+
if platform.system() == 'Windows':
172+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
173+
async with websockets.connect("ws://127.0.0.1:3928/events") as websocket:
174+
try:
175+
# Using wait_for instead of timeout context manager
176+
async def receive_until_success():
177+
while True:
178+
message = await websocket.recv()
179+
try:
180+
event = json.loads(message)
181+
if event.get("type") == "DownloadSuccess":
182+
return event
183+
except json.JSONDecodeError:
184+
continue
185+
186+
return await asyncio.wait_for(receive_until_success(), timeout)
187+
188+
except asyncio.TimeoutError:
189+
raise TimeoutError("Timeout waiting for DownloadSuccess event")

0 commit comments

Comments
 (0)