Implement flag handling and migration status checks; refactor database test functions and update requirements
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
||||
import auth.api_security as auth
|
||||
import time
|
||||
import threading
|
||||
from tests import db_test
|
||||
|
||||
try:
|
||||
os.remove("api.log")
|
||||
@@ -43,24 +44,39 @@ def run_migration():
|
||||
)
|
||||
process.wait()
|
||||
migration_done = (process.returncode == 0)
|
||||
with open("migration_status.flag", "w") as f:
|
||||
f.write("done" if migration_done else "failed")
|
||||
with open("flags/migration_status.flag", "w") as f:
|
||||
f.write("migration_done" if migration_done else "failed")
|
||||
|
||||
thread = threading.Thread(target=run_migration)
|
||||
thread.start()
|
||||
|
||||
|
||||
#DB test
|
||||
def run_db_test():
|
||||
tokens = db_test.test_table("tokens", ["tokens", "time", "end_date"])
|
||||
user = db_test.test_table("user", ["username", "password", "role"])
|
||||
items = db_test.test_table("luggage", ["clothes", "weight", "pieces"])
|
||||
time.sleep(5)
|
||||
if tokens == True & user == True & items == True:
|
||||
with open("flags/db.flag", "w") as f:
|
||||
f.write("db_check_done")
|
||||
else:
|
||||
os._exit(1)
|
||||
|
||||
#cli and api
|
||||
log_file = open("api_server.log", "w", encoding="utf-8")
|
||||
api_process = subprocess.Popen(
|
||||
["fastapi", "dev", "api_server.py"],
|
||||
["fastapi", "dev", "api_server.py", "--reload-dir", "web", "--reload-dir", "api", "--reload-dir", "api_server.py",],
|
||||
stdout=log_file,
|
||||
stderr=log_file,
|
||||
env=env
|
||||
)
|
||||
cli_process = subprocess.Popen([sys.executable, "cli.py"])
|
||||
|
||||
api_process.wait()
|
||||
cli_process.wait()
|
||||
db_thread = threading.Thread(target=run_db_test)
|
||||
db_thread.start()
|
||||
thread = threading.Thread(target=run_migration)
|
||||
thread.start()
|
||||
threading.Thread(target=api_process.wait, daemon=True).start()
|
||||
threading.Thread(target=cli_process.wait, daemon=True).start()
|
||||
|
||||
# automatic durataion validation check
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user