Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ciioprof0 committed Aug 18, 2024
1 parent 0408206 commit 740e061
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ling508/tests/test_95_e2e_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

""" End-to-end test for the Flask app """

isinstance
import os
import requests
import time
Expand All @@ -16,6 +17,8 @@
from selenium.webdriver.support import expected_conditions as EC
from ling508.api import app

logging.basicConfig(level=logging.INFO)

@pytest.fixture(scope="module")
def test_client():
"""Fixture to create a test client for the Flask app."""
Expand All @@ -42,18 +45,21 @@ def init_driver():

def run_flask_app():
"""Start the Flask app in a separate process."""
logging.info("Attempting to start the Flask app...")
app.run(host="0.0.0.0", port=5000, debug=False, use_reloader=False)

def wait_for_flask():
"""Wait until the Flask app is responsive."""
for _ in range(30): # Retry 30 times with 1-second intervals
for i in range(30): # Retry 30 times with 1-second intervals
try:
response = requests.get("http://localhost:5000/")
if response.status_code == 200:
logging.info(f"Flask app responded successfully on attempt {i + 1}.")
return True
except requests.exceptions.ConnectionError:
pass
logging.warning(f"Attempt {i + 1}: Flask app not yet responsive.")
time.sleep(1)
logging.error("Flask app did not start within the expected time.")
return False

def test_form_submission(init_driver, test_client):
Expand All @@ -78,7 +84,6 @@ def test_form_submission(init_driver, test_client):
)

# Use a local path to the file within the same repo
# Construct the absolute path to the lexicon file
lexicon_file_path = os.path.join(os.getcwd(), 'lexicon', 'test_clex.pl')
uri_field.send_keys(lexicon_file_path)

Expand All @@ -95,4 +100,4 @@ def test_form_submission(init_driver, test_client):
finally:
# Terminate the Flask server process
flask_process.terminate()
flask_process.join()
flask_process.join()

0 comments on commit 740e061

Please sign in to comment.