Skip to content

Commit

Permalink
test: add tests for launch
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioHeredia committed May 15, 2024
1 parent 2f9fd09 commit 5120062
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
import routes
import test_secrets
import test_stats
import test_launch
28 changes: 28 additions & 0 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Test if PAPI launches correctly.
Sometimes can fail, especially with the @repeat_every() task (fastapi_utils
package error).
"""

import subprocess
import requests
import time


server_process = subprocess.Popen(
['uvicorn', 'ai4papi.main:app', '--host', '0.0.0.0', '--port', '8080'],
stdout=subprocess.DEVNULL,
stderr = subprocess.DEVNULL,
)
time.sleep(15) # wait for PAPI to start

try:
response = requests.get("http://0.0.0.0:8080")
assert response.status_code == 200, "PAPI status code is not 200"
except requests.exceptions.ConnectionError:
raise Exception("Failed to connect to the server")
finally:
server_process.kill()

print("PAPI launch tests successful!")

0 comments on commit 5120062

Please sign in to comment.