Skip to content

Commit 3753c39

Browse files
committed
Refactor executing the test.
- Port all improvement done in previous version - allow to run test in parallele of update (using different .env file)
1 parent 75ba6e4 commit 3753c39

File tree

8 files changed

+57
-37
lines changed

8 files changed

+57
-37
lines changed

src/.gitlab-ci.yml.jinja

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -303,55 +303,35 @@ lint:
303303
# can be run sooner
304304
needs: ["fetch"]
305305

306-
307306
test:
308307
stage: test
309308
script:
310309
- CURRENT_PATH=`pwd`
311310
- cd ~gitlab-runner/builds/${AK_WORKING_DIR}
312-
# get list of modules to test
313-
# add back --select-exclude ${EXCLUDE_MODULES:-none} from a path
314-
# qu'est ce que ça fait ça ?
315-
#- docker compose run odoo initdb ${DB_NAME} --cache-prefix ${CI_PROJECT_NAME:0:7}
316-
# TODO: réflechir si on laisse ça ici ou dans le conteneur
317-
318-
# list of all local-src modules
319-
- ADDONS_TEST=$(manifestoo --select-addons-dir odoo/local-src list --separator=,)
320-
- ADDONS_TEST_DEP=$(manifestoo --select-addons-dir odoo/local-src list-depends --separator=,)
321-
- echo $ADDONS_TEST
322-
- echo $ADDONS_TEST_DEP
323-
# start from a clean state
324-
- docker compose --profile db run --rm bedrock dropdb --force --if-exists ${BUILD_NAME}_test
325-
# --labels traefik.enable=false in order to not mess with the review
326-
# init db with dependencies of our modules
327-
# we force PG port in order to bypass pgbouncer
328-
- docker compose run --labels traefik.enable=false -e DB_NAME="${BUILD_NAME}_test" -e PGDATABASE="${BUILD_NAME}_test" -e "PGPORT=5432" -e "DB_PORT=5432" --rm odoo click-odoo-initdb -n ${BUILD_NAME}_test -m ${ADDONS_TEST_DEP} --cache-prefix ${CI_PROJECT_NAME:0:7}
329-
# run the tests here
330-
- docker compose run --labels traefik.enable=false -e DB_NAME="${BUILD_NAME}_test" -e PGDATABASE="${BUILD_NAME}_test" --rm --workdir /data/odoo/filestore odoo coverage run --include "/odoo/local-src/*" --branch /odoo/bin/odoo --stop-after-init -i ${ADDONS_TEST} --test-enable --workers=0
331-
# display report in MR
332-
- docker compose run --labels traefik.enable=false -e DB_NAME="${BUILD_NAME}_test" -e PGDATABASE="${BUILD_NAME}_test" --rm --workdir /data/odoo/filestore odoo coverage report
333-
# export for the artifacts
334-
- docker compose run --labels traefik.enable=false -e DB_NAME="${BUILD_NAME}_test" -e PGDATABASE="${BUILD_NAME}_test" --rm --workdir /data/odoo/filestore odoo coverage xml --skip-empty
335-
# extract coverage report
336-
- docker compose cp odoo:/data/odoo/filestore/coverage.xml coverage.xml
337-
# move coverage report to accessible location from gitlab-ci
338-
- cp coverage.xml ${CURRENT_PATH}/coverage.xml
311+
- cp .env .env-test
312+
- echo "ENABLE_TRAEFIK=false" >> .env-test
313+
- echo "COMPOSE_PROJECT_NAME=${BUILD_NAME}_test" >> .env-test
314+
- echo "PGDATABASE=${BUILD_NAME}_test" >> .env-test
315+
- docker compose --env-file .env-test kill
316+
- dropdb --force --if-exists ${BUILD_NAME}_test
317+
- docker compose --env-file .env-test run --rm odoo initdb ${BUILD_NAME}_test --cache-prefix ${CI_PROJECT_NAME:0:7}
318+
- docker compose --env-file .env-test run --rm odoo runtests
319+
- mv shared $CURRENT_PATH/
339320
rules:
340321
# Run tests in MR if there is no Skiptest tag
341322
- if: $AK_IS_MR == "true" && $CI_MERGE_REQUEST_LABELS !~ /Skiptest/
323+
# Always run test in major branch
324+
- if: $AK_IS_MAJOR_BRANCH == "true" && $AK_DO_OPENUPGRADE_MIGRATION != "true"
342325
needs:
343-
# update_db do a docker compose stop, we don't want to be halted
344-
# if this job start sooner
345-
# optional true, let us the ability to run if update_db is cancelled
346-
- job: "update_db"
347-
optional: true
348-
allow_failure: true
349-
coverage: '/TOTAL(\W+\d+){5}\%/'
326+
- job: "build"
327+
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
350328
artifacts:
329+
when: always
351330
reports:
331+
junit: shared/test_results/*.xml
352332
coverage_report:
353333
coverage_format: cobertura
354-
path: coverage.xml
334+
path: shared/coverage.xml
355335

356336
# Run the container used for the review
357337
review:

src/ci.docker-compose.yml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
PGPORT: 6432
4141
{% endif %}
4242
labels:
43-
- "traefik.enable=true"
43+
- "traefik.enable=${ENABLE_TRAEFIK:-true}"
4444
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${DOMAIN}`)"
4545
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.tls=false"
4646
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}-long.rule=Host(`${DOMAIN}`) && PathPrefix(`/longpolling/`)"

src/odoo/Dockerfile.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ COPY ./src/odoo/tools /odoo/src/odoo/tools
2222
COPY ./src/odoo/upgrade /odoo/src/odoo/upgrade
2323
RUN /odoo/bin/pip install -e /odoo/src
2424

25+
COPY bin/* /usr/local/bin/
26+
2527
FROM base as thisproject
2628
COPY ./requirements.txt /odoo/requirements.txt
2729
RUN /odoo/bin/pip install --no-cache-dir \

src/odoo/bin/initdb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
# Usage: initdb dbtest
5+
6+
echo "Create database $1"
7+
8+
EXTRA_ARGS="${@:2}"
9+
ADDONS_INIT=$(manifestoo --select-exclude ${EXCLUDE_MODULES:-none} --select-addons-dir /odoo/local-src list-depends --separator=,)
10+
11+
# Some module like product_code_unique can break the installation if their are installed too early, so you can use the variable "EXCLUDE_DEPENDENCIES" to exclude them
12+
13+
export ADDONS_INIT
14+
ADDONS_INIT=l10n_generic_coa,$(python3 -c "import os; print(','.join([x for x in os.environ.get('ADDONS_INIT').split(',') if x not in os.environ.get('EXCLUDE_DEPENDENCIES', '').split(',')]))")
15+
16+
click-odoo-initdb -n $1 -m ${ADDONS_INIT} ${EXTRA_ARGS}

src/odoo/bin/runtests

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
# Usage: runtest
5+
6+
# Run tests. Use unbuffer to get a colored output.
7+
8+
ADDONS_TEST=$(manifestoo --select-exclude ${EXCLUDE_MODULES:-none} --select-addons-dir /odoo/local-src list --separator=,)
9+
# Move to shared folder so coverage file will be shared with the host
10+
# and so accessible by the gitlab runner
11+
cd /odoo/shared
12+
unbuffer coverage run --include "/odoo/local-src/*" --branch $(which odoo) --stop-after-init -i ${ADDONS_TEST} --test-enable --workers=0
13+
ls -alh
14+
coverage report -i --precision=2 --skip-empty
15+
coverage xml -i -o coverage.xml
16+
17+
sed -i "s=<source></source>=<source>/home/gitlab-runner/builds</source>=g" /odoo/shared/coverage.xml
18+
sed -i "s=/odoo/local-src=${CI_PROJECT_DIR}/odoo/local-src=g" /odoo/shared/coverage.xml
19+
sed -i "s=/home/gitlab-runner/builds/=builds/=g" /odoo/shared/coverage.xml

src/odoo/local-src/custom_all/__manifest__.py.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"auth_oidc_akretion_data",
1717
"auth_oidc_environment",
1818
"database_age_cron",
19+
"odoo_test_xmlrunner",
1920
"server_environment_ir_config_parameter",
2021
"web_environment_ribbon",
2122
],

src/odoo/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pyjwt # auth_oidc
33
python-jose[cryptography] # auth_oidc
44
#sentry 1.9.0 fixé dans le manifest du module sentry pour le moment
55
sentry-sdk<=1.9.0
6+
unittest-xml-reporting # odoo_test_xmlrunner
67

78
#apispec #shopinvader
89
#boto3==1.20.32 # shopinvader

src/odoo/spec.yaml.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ server-tools:
2525
modules:
2626
- sentry
2727
- bus_alt_connection
28+
- odoo_test_xmlrunner
2829
src: https://github.com/oca/server-tools {{ odoo_version }}
2930

3031
web:

0 commit comments

Comments
 (0)