diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe592d8140f0e311f784b2c825a634b19e2129d7..b7a9c8f96fce0a2c634f99f7349c7a240bbff6b7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,7 +17,7 @@ ci_frontend: ci_backend: stage: ci script: - - docker-compose run --rm mcserver bash -c "source ../venv/bin/activate && coverage run --rcfile=.coveragerc tests.py && coverage combine && coverage report -m" > ci_backend.log + - docker-compose run --rm --entrypoint="./coverage_backend.sh" mcserver > ci_backend.log artifacts: paths: - ci_backend.log diff --git a/coverage_local.sh b/coverage_local.sh index ae86b1287c63edaafcdae3ccdbdd61b8edd8f6ad..5b398e71b07a19f2981efe1c7d61514b09d4ad2a 100755 --- a/coverage_local.sh +++ b/coverage_local.sh @@ -1,5 +1,5 @@ docker-compose build -docker-compose run --rm --entrypoint="npm run test-ci" mc_frontend > ci_frontend.log -docker-compose run --rm mcserver bash -c "source ../venv/bin/activate && coverage run --rcfile=.coveragerc tests.py && coverage combine && coverage report -m" > ci_backend.log +docker-compose run --rm --entrypoint="npm run test-ci" mc_frontend >ci_frontend.log +docker-compose run --rm --entrypoint="./coverage_backend.sh" mcserver > ci_backend.log ./coverage_ci.sh cat coverage.log diff --git a/mc_backend/.coveragerc b/mc_backend/.coveragerc index 652a2c47e50548ab99b979c143d0b27d056424e1..55b70aa4cf8936b10573db2c5e62355c27eddc08 100644 --- a/mc_backend/.coveragerc +++ b/mc_backend/.coveragerc @@ -17,5 +17,6 @@ exclude_lines = # Don't complain if non-runnable code isn't run: if __name__ == .__main__.: except ModuleNotFoundError: +fail_under = 100 ignore_errors = True show_missing = True diff --git a/mc_backend/coverage_backend.sh b/mc_backend/coverage_backend.sh new file mode 100755 index 0000000000000000000000000000000000000000..c23bbe336c7b9a358e5b591a395e5a45e7aee1f6 --- /dev/null +++ b/mc_backend/coverage_backend.sh @@ -0,0 +1,4 @@ +#!/bin/bash +source ../venv/bin/activate +coverage run --rcfile=.coveragerc tests.py +coverage combine && coverage report -m diff --git a/mc_backend/mcserver/app/__init__.py b/mc_backend/mcserver/app/__init__.py index 38857e446d531df45351f25f48160f45b1cfb611..5f27b2ab1a4528b8196e7b81c57a24f6702681f0 100644 --- a/mc_backend/mcserver/app/__init__.py +++ b/mc_backend/mcserver/app/__init__.py @@ -18,14 +18,6 @@ from flask_sqlalchemy import SQLAlchemy from open_alchemy import init_yaml from mcserver.config import Config -# remove stale connections from the connection pool after 1 hour -db: SQLAlchemy = SQLAlchemy() # session_options={"autocommit": True, "pool_recycle": 3600} -migrate: Migrate = Migrate(directory=Config.MIGRATIONS_DIRECTORY) -if not hasattr(open_alchemy.models, Config.DATABASE_TABLE_CORPUS): - # do this _BEFORE_ you add any APIs to your application - init_yaml(Config.API_SPEC_MODELS_YAML_FILE_PATH, base=db.Model, - models_filename=os.path.join(Config.MC_SERVER_DIRECTORY, "models_auto.py")) - def apply_event_handlers(app: FlaskApp): """Applies event handlers to a given Flask application, such as logging after requests or teardown logic.""" @@ -64,6 +56,11 @@ def create_app(cfg: Type[Config] = Config) -> Flask: return app +def create_database() -> SQLAlchemy: + """Creates a new connection to a database, which will handle all future database transactions.""" + return SQLAlchemy() # session_options={"autocommit": True} + + def full_init(app: Flask, cfg: Type[Config] = Config) -> None: """ Fully initializes the application, including logging.""" from mcserver.app.services import DatabaseService @@ -145,6 +142,13 @@ def shutdown_session(exception=None): db.session.remove() +db: SQLAlchemy = create_database() +migrate: Migrate = Migrate(directory=Config.MIGRATIONS_DIRECTORY) +if not hasattr(open_alchemy.models, Config.DATABASE_TABLE_CORPUS): + # do this _BEFORE_ you add any APIs to your application + init_yaml(Config.API_SPEC_MODELS_YAML_FILE_PATH, base=db.Model, + models_filename=os.path.join(Config.MC_SERVER_DIRECTORY, "models_auto.py")) + # import the models so we can access them from other parts of the app using imports from "app.models"; # this has to be at the bottom of the file from mcserver.app import models diff --git a/mc_backend/mcserver/config.py b/mc_backend/mcserver/config.py index 13191babb6434c2375bf78fa14038b4bba4d76fd..0a5267055b295b6c66d957302f893d79d15a56c4 100644 --- a/mc_backend/mcserver/config.py +++ b/mc_backend/mcserver/config.py @@ -145,6 +145,8 @@ class Config(object): SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL") or DATABASE_URL_SQLITE # BEWARE: if True, logs every single database statement executed by this application to STDOUT SQLALCHEMY_ECHO = False + # remove stale connections from the connection pool after 1 hour + SQLALCHEMY_POOL_RECYCLE = 3600 SQLALCHEMY_TRACK_MODIFICATIONS = False STATIC_EXERCISES_REPOSITORY_URL = "https://scm.cms.hu-berlin.de/callidus/machina-callida/-/archive/master/machina-callida-master.zip?path=mc_frontend%2Fsrc%2Fassets%2Fh5p" STOP_WORDS_LATIN_PATH = os.path.join(CACHE_DIRECTORY, "stop_words_latin.json") diff --git a/mc_frontend/src/app/helper.service.ts b/mc_frontend/src/app/helper.service.ts index b5cfab698f7530e7751e43d0d24a97159ad96aa9..84a9cd34391f4654f5d68c146cf9f0c2e33b2ca2 100644 --- a/mc_frontend/src/app/helper.service.ts +++ b/mc_frontend/src/app/helper.service.ts @@ -259,7 +259,7 @@ export class HelperService { configMC.backendBaseUrl = part1.concat(configMC.backendBaseApiPath).concat('/'); } if (!configMC.frontendBaseUrl) { - configMC.frontendBaseUrl = location.href.substring(0, location.href.lastIndexOf('/') + 1); + configMC.frontendBaseUrl = location.href.substring(0, location.href.lastIndexOf('/')); } }