Skip to content

Commit 1204320

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 d985e9a commit 1204320

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

src/.gitlab-ci.yml.jinja

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -311,55 +311,37 @@ lint:
311311
# can be run sooner
312312
needs: ["fetch"]
313313

314-
315314
test:
316315
stage: test
317316
script:
318317
- CURRENT_PATH=`pwd`
319318
- cd ~gitlab-runner/builds/${AK_WORKING_DIR}
320-
# get list of modules to test
321-
# add back --select-exclude ${EXCLUDE_MODULES:-none} from a path
322-
# qu'est ce que ça fait ça ?
323-
#- docker compose run odoo initdb ${DB_NAME} --cache-prefix ${CI_PROJECT_NAME:0:7}
324-
# TODO: réflechir si on laisse ça ici ou dans le conteneur
325-
326-
# list of all local-src modules
327-
- ADDONS_TEST=$(manifestoo --select-addons-dir odoo/local-src list --separator=,)
328-
- ADDONS_TEST_DEP=$(manifestoo --select-addons-dir odoo/local-src list-depends --separator=,)
329-
- echo $ADDONS_TEST
330-
- echo $ADDONS_TEST_DEP
331-
# start from a clean state
332-
- docker compose --profile db run --rm bedrock dropdb --force --if-exists ${BUILD_NAME}_test
333-
# --labels traefik.enable=false in order to not mess with the review
334-
# init db with dependencies of our modules
335-
# we force PG port in order to bypass pgbouncer
336-
- 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}
337-
# run the tests here
338-
- 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
339-
# display report in MR
340-
- 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
341-
# export for the artifacts
342-
- 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
343-
# extract coverage report
344-
- docker compose cp odoo:/data/odoo/filestore/coverage.xml coverage.xml
345-
# move coverage report to accessible location from gitlab-ci
346-
- cp coverage.xml ${CURRENT_PATH}/coverage.xml
319+
- cp .env .env-test
320+
- echo "ENABLE_TRAEFIK=false" >> .env-test
321+
- echo "COMPOSE_PROJECT_NAME=${BUILD_NAME}_test" >> .env-test
322+
- echo "PGDATABASE=${BUILD_NAME}_test" >> .env-test
323+
- docker compose --env-file .env-test kill
324+
- dropdb --force --if-exists ${BUILD_NAME}_test
325+
- export ODOO_MIGRATION=demo
326+
- docker compose --env-file .env-test run --rm odoo initdb ${BUILD_NAME}_test --cache-prefix ${CI_PROJECT_NAME:0:7}
327+
- ./odoo/bin/prehook_test
328+
- docker compose --env-file .env-test run --rm odoo runtests
329+
- mv shared $CURRENT_PATH/
347330
rules:
348331
# Run tests in MR if there is no Skiptest tag
349332
- if: $AK_IS_MR == "true" && $CI_MERGE_REQUEST_LABELS !~ /Skiptest/
333+
# Always run test in major branch
334+
- if: $AK_IS_MAJOR_BRANCH == "true" && $AK_DO_OPENUPGRADE_MIGRATION != "true"
350335
needs:
351-
# update_db do a docker compose stop, we don't want to be halted
352-
# if this job start sooner
353-
# optional true, let us the ability to run if update_db is cancelled
354-
- job: "update_db"
355-
optional: true
356-
allow_failure: true
357-
coverage: '/TOTAL(\W+\d+){5}\%/'
336+
- job: "build"
337+
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
358338
artifacts:
339+
when: always
359340
reports:
341+
junit: shared/test_results/*.xml
360342
coverage_report:
361343
coverage_format: cobertura
362-
path: coverage.xml
344+
path: shared/coverage.xml
363345

364346
# Run the container used for the review
365347
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/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

0 commit comments

Comments
 (0)