From d5e59822d453d0933e1d9414f271198e589b8926 Mon Sep 17 00:00:00 2001 From: Mike Kot Date: Mon, 10 Jul 2023 18:58:13 +0300 Subject: [PATCH 1/2] copy whl from outer context; stop on fail --- .github/workflows/workflow.yml | 15 +++++++++----- CONTRIBUTING.md | 2 +- Makefile | 9 -------- README.md | 33 +++++++++++++++++++++++++----- tests/configuration.py | 2 +- tests/environment.py | 4 ++-- tests/images/clickhouse/Dockerfile | 2 +- tests/images/zookeeper/Dockerfile | 2 +- tests/modules/compose.py | 4 ++-- 9 files changed, 46 insertions(+), 27 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4f890c1c..59c16550 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -87,15 +87,20 @@ jobs: - {name: run unit tests, run: pytest} - - name: prepare docker images for integration tests - run: CLICKHOUSE_VERSION=${{ matrix.clickhouse }} make test-integration-prepare - + - name: prepare integration tests + run: | + cd tests + CLICKHOUSE_VERSION=${{ matrix.clickhouse }} python3 -m env_control create + cd .. + - name: run integration tests - run: make test-integration + run: | + cd tests + behave --show-timings --junit -D skip_setup + cd .. - name: publish test report uses: mikepenz/action-junit-report@v3 if: always() with: report_paths: 'tests/reports/*.xml' - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8787b6be..450237c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## General info -Hello! In order for us (YANDEX LLC) to accept patches and other contributions from you, you will have to adopt our Yandex Contributor License Agreement (the “**CLA**”). The current version of the CLA can be found here: +Hello! In order for us (YANDEX LLC) to accept patches and other contributions from you, you will have to adopt our Yandex Contributor License Agreement (the "**CLA**"). The current version of the CLA can be found here: 1) https://yandex.ru/legal/cla/?lang=en (in English) and 2) https://yandex.ru/legal/cla/?lang=ru (in Russian). diff --git a/Makefile b/Makefile index 90c0a613..bf2847d0 100644 --- a/Makefile +++ b/Makefile @@ -82,15 +82,6 @@ version.txt: build-deb-package: prepare-changelog cd debian && debuild --check-dirname-level 0 --preserve-env --no-lintian --no-tgz-check -uc -us -export CLICKHOUSE_VERSION?=latest - -test-integration-prepare: - cp dist/*.whl tests/ - cd tests && CLICKHOUSE_VERSION=${CLICKHOUSE_VERSION} python3 -m env_control create - -test-integration: - cd tests && behave --show-timings -D skip_setup --junit - .PHONY: help help: @echo "Base targets:" diff --git a/README.md b/README.md index 9fb1f559..ca7df611 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,43 @@ All of these tools must be run on the same host as ClickHouse server is running. ## Local development (using venv) -```bash +```sh python3 -m venv venv source venv/bin/activate pip install .[test] -flit install flit build --no-use-vcs +flit install # lint black . isort . -# run tests +# unit tests pytest -CLICKHOUSE_VERSION="1.2.3.4" make test-integration-prepare -make test-integration +# integration tests (rebuild docker images using a .whl file) +cd tests; behave + +# integration tests (do not rebuild docker images) +# useful when you didn't change source code +cd tests; behave -D skip_setup + +# integration tests (supply a custom ClickHouse version to test against) +cd tests; CLICKHOUSE_VERSION="1.2.3.4" behave + +# If you want to have containers running on failure, supply a flag: +# behave -D no_stop_on_fail +``` + +Please note: base images for tests are pulled from [chtools Dockerhub](https://hub.docker.com/u/chtools). +If you want to build base images locally, run + +```sh +docker buildx bake -f tests/bake.hcl +``` + +If you want to build base images for multiple versions of ClickHouse, run: + +```sh +CLICKHOUSE_VERSIONS='1.2.3.4, 5.6.7.8, latest' docker buildx bake -f tests/bake.hcl ``` diff --git a/tests/configuration.py b/tests/configuration.py index 19447648..f279bc11 100644 --- a/tests/configuration.py +++ b/tests/configuration.py @@ -18,7 +18,7 @@ def create(): }, "depends_on": ["zookeeper"], "args": { - "CLICKHOUSE_VERSION": "$CLICKHOUSE_VERSION", + "CLICKHOUSE_VERSION": "${CLICKHOUSE_VERSION:-latest}", }, "db": { "user": "reader", diff --git a/tests/environment.py b/tests/environment.py index 1ff384a9..a3c51e36 100644 --- a/tests/environment.py +++ b/tests/environment.py @@ -52,7 +52,7 @@ def after_all(context): """ Clean up. """ - if context.failed and not context.aborted: - logging.warning("Remember to run `make clean` after you done") + if (context.failed and not context.aborted) and context.config.userdata.getbool("no_stop_on_fail"): + logging.info("Not stopping containers on failure as requested") return env_control.stop(context) diff --git a/tests/images/clickhouse/Dockerfile b/tests/images/clickhouse/Dockerfile index e8024662..6f0a3c6e 100644 --- a/tests/images/clickhouse/Dockerfile +++ b/tests/images/clickhouse/Dockerfile @@ -1,5 +1,5 @@ ARG CLICKHOUSE_VERSION FROM chtools/test-clickhouse:$CLICKHOUSE_VERSION -COPY *.whl / +COPY dist/*.whl / RUN pip3 install *.whl diff --git a/tests/images/zookeeper/Dockerfile b/tests/images/zookeeper/Dockerfile index 168d64ec..20e7b760 100644 --- a/tests/images/zookeeper/Dockerfile +++ b/tests/images/zookeeper/Dockerfile @@ -1,4 +1,4 @@ FROM chtools/test-zookeeper -COPY *.whl / +COPY dist/*.whl / RUN python3 -m pip install *.whl diff --git a/tests/modules/compose.py b/tests/modules/compose.py index 65c0fd97..c8a240a7 100644 --- a/tests/modules/compose.py +++ b/tests/modules/compose.py @@ -148,7 +148,7 @@ def _generate_service_config( All paths are relative to the location of compose-config.yaml (which is ./staging/compose-config.yaml by default) """ - staging_dir = config["staging_dir"] + staging_dir = "tests/" + config["staging_dir"] network_name = config["network_name"] volumes = [f"./images/{instance_name}/config:/config:rw"] @@ -164,7 +164,7 @@ def _generate_service_config( service = { "build": { - "context": "..", + "context": "../..", "dockerfile": f"{staging_dir}/images/{instance_name}/Dockerfile", "args": instance_config.get("args", []), }, From 536c1edebcd3b8f98ef6a00c2b550a4ddf493e72 Mon Sep 17 00:00:00 2001 From: Mike Kot Date: Mon, 10 Jul 2023 19:00:09 +0300 Subject: [PATCH 2/2] fix --- tests/environment.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/environment.py b/tests/environment.py index a3c51e36..fb2a2947 100644 --- a/tests/environment.py +++ b/tests/environment.py @@ -52,7 +52,9 @@ def after_all(context): """ Clean up. """ - if (context.failed and not context.aborted) and context.config.userdata.getbool("no_stop_on_fail"): + if (context.failed and not context.aborted) and context.config.userdata.getbool( + "no_stop_on_fail" + ): logging.info("Not stopping containers on failure as requested") return env_control.stop(context)