Fix Server Startup test
This commit is contained in:
parent
fe55071849
commit
9aac3399e7
2 changed files with 20 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -13,6 +13,8 @@ __pycache__/
|
|||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
mise.toml
|
||||
|
||||
full_run.ipynb
|
||||
|
||||
# C extensions
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from logging import getLogger
|
||||
import unittest
|
||||
import subprocess
|
||||
import time
|
||||
|
|
@ -8,6 +9,10 @@ from pathlib import Path
|
|||
import sys
|
||||
import uuid
|
||||
|
||||
from tenacity import retry, stop_after_attempt, wait_fixed
|
||||
|
||||
from cognee.api.health import HealthStatus
|
||||
|
||||
|
||||
class TestCogneeServerStart(unittest.TestCase):
|
||||
@classmethod
|
||||
|
|
@ -27,9 +32,8 @@ class TestCogneeServerStart(unittest.TestCase):
|
|||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
preexec_fn=os.setsid,
|
||||
)
|
||||
# Give the server some time to start
|
||||
time.sleep(35)
|
||||
)
|
||||
cls.wait_for_server_startup()
|
||||
|
||||
# Check if server started with errors
|
||||
if cls.server_process.poll() is not None:
|
||||
|
|
@ -49,12 +53,18 @@ class TestCogneeServerStart(unittest.TestCase):
|
|||
cls.server_process.terminate()
|
||||
cls.server_process.wait()
|
||||
|
||||
@classmethod
|
||||
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||
def wait_for_server_startup(cls):
|
||||
response = requests.get("http://localhost:8000/health", timeout=15)
|
||||
status_str = response.json().get("status")
|
||||
if response.status_code == 200 and status_str == "ready":
|
||||
return True
|
||||
else:
|
||||
getLogger().info(f"Health check status {response.status_code} : {status_str}, retrying...")
|
||||
raise requests.exceptions.RequestException(f"Server is {status_str}")
|
||||
|
||||
def test_server_is_running(self):
|
||||
"""Test that the server is running and can accept connections."""
|
||||
# Test health endpoint
|
||||
health_response = requests.get("http://localhost:8000/health", timeout=15)
|
||||
self.assertIn(health_response.status_code, [200])
|
||||
|
||||
# Test root endpoint
|
||||
root_response = requests.get("http://localhost:8000/", timeout=15)
|
||||
self.assertEqual(root_response.status_code, 200)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue