Skip to content

Commit

Permalink
feat: e2e tests within docker
Browse files Browse the repository at this point in the history
- we split out e2e tests into own folder

- e2e tests will run against the service in docker compose

- we start by splitting out the prometheus and kafka e2e tests which do not need local running services
  • Loading branch information
nosahama committed Nov 27, 2024
1 parent 9155fdb commit 6225ae5
Show file tree
Hide file tree
Showing 27 changed files with 667 additions and 90 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/tests-in-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Tests in Docker

on:
pull_request:
types: [ opened, synchronize, reopened ]
push:
branches: [ main ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 1
PIP_PROGRESS_BAR: off
PYTHONUNBUFFERED: 1
KARAPACE_DOTENV: ${{ github.workspace }}/karapace.config.env

jobs:
unit-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12' ]
env:
PYTEST_ADDOPTS: >-
--log-dir=/tmp/ci-logs
--log-file=/tmp/ci-logs/pytest.log
--showlocals
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
cache: pip
python-version: ${{ matrix.python-version }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.0'

- name: Install requirements
run: make install

- name: Resolve Karapace version
run: |
source ./venv/bin/activate
KARAPACE_VERSION=$(python -c "from karapace import version; print(version.__version__)")
echo KARAPACE_VERSION=$KARAPACE_VERSION >> $GITHUB_ENV
- name: Run containers
run: KARAPACE_VERSION=${{ env.KARAPACE_VERSION }} docker compose --file=container/compose.yml up --build --wait --detach

- run: make install-dev

- run: make unit-tests-in-docker
env:
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=src --cov-append --numprocesses 4"

- run: make e2e-tests-in-docker
env:
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=src --cov-append --numprocesses 4"

coverage:
name: Coverage report
runs-on: ubuntu-latest
needs: tests
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4

- run: make install-dev

- name: Download coverage
id: download_coverage
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true

- name: Post coverage comment
id: post_coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERGE_COVERAGE_FILES: true

- name: Store PR comment to be posted
uses: actions/upload-artifact@v4
if: steps.post_coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
name: python-coverage-comment-action
path: python-coverage-comment-action.txt
39 changes: 8 additions & 31 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ env:
FORCE_COLOR: 1
PIP_PROGRESS_BAR: off
PYTHONUNBUFFERED: 1
KARAPACE_DOTENV: ${{ github.workspace }}/karapace.config.env

jobs:
unit-tests:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -41,8 +40,8 @@ jobs:
with:
go-version: '1.21.0'

- name: Install requirements
run: make install
- name: Create virtual environment & install requirements
run: make install-dev

- name: Resolve Karapace version
run: |
Expand All @@ -53,49 +52,27 @@ jobs:
- name: Run containers
run: KARAPACE_VERSION=${{ env.KARAPACE_VERSION }} docker compose --file=container/compose.yml up --build --wait --detach

- run: make install-dev
- run: make unit-tests-in-docker
env:
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=src --cov-append --numprocesses 4"
KARAPACE_VERSION=: ${{ env.KARAPACE_VERSION }}

integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12' ]
env:
PYTEST_ADDOPTS: >-
--log-dir=/tmp/ci-logs
--log-file=/tmp/ci-logs/pytest.log
--showlocals
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
cache: pip
python-version: ${{ matrix.python-version }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.0'
- run: make e2e-tests-in-docker
env:
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=src --cov-append --numprocesses 4"

- run: make integration-tests
env:
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
PYTEST_ARGS: "--cov=src --cov-append --random-order --numprocesses 4"
PYTEST_ARGS: "--cov=karapace --cov-append --random-order --numprocesses 4"

- name: Archive logs
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: karapace-integration-test-logs-${{ matrix.python-version }}
path: /tmp/ci-logs

- name: Archive coverage file
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
__pycache__/
/build/
/dist/
/karapace.egg-info/
src/karapace.egg-info/
/karapace-rpm-src.tar
/kafka_*.tgz
/kafka_*/
venv
/karapace/version.py
src/karapace/version.py
.run
.python-version
.hypothesis/
Expand Down
8 changes: 8 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ unit-tests-in-docker:
rm -fr runtime/*
$(KARAPACE-CLI) $(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/unit/
rm -fr runtime/*

.PHONY: e2e-tests-in-docker
e2e-tests-in-docker: export PYTEST_ARGS ?=
e2e-tests-in-docker:
rm -fr runtime/*
sleep 10
$(KARAPACE-CLI) $(PYTHON) -m pytest -s -vvv $(PYTEST_ARGS) tests/e2e/
rm -fr runtime/*
3 changes: 3 additions & 0 deletions container/karapace.registry.env
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ STATSD_PORT=8125
KAFKA_SCHEMA_READER_STRICT_MODE=False
KAFKA_RETRIABLE_ERRORS_SILENCED=True
USE_PROTOBUF_FORMATTER=False
HTTP_REQUEST_MAX_SIZE=1048576
REST_BASE_URI=http://karapace-rest-proxy:8082
TAGS='{ "app": "karapace-schema-registry" }'
1 change: 1 addition & 0 deletions container/karapace.rest.env
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ KAFKA_SCHEMA_READER_STRICT_MODE=False
KAFKA_RETRIABLE_ERRORS_SILENCED=True
USE_PROTOBUF_FORMATTER=False
HTTP_REQUEST_MAX_SIZE=1048576
REST_BASE_URI=http://karapace-rest-proxy:8082
TAGS='{ "app": "karapace-rest-proxy" }'
10 changes: 7 additions & 3 deletions karapace.config.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ACCESS_LOGS_DEBUG=False
ACCESS_LOG_CLASS=aiohttp.web_log.AccessLogger
ADVERTISED_HOSTNAME=127.0.0.1
ADVERTISED_PORT=8081
ADVERTISED_PROTOCOL=http
BOOTSTRAP_URI=127.0.0.1:9092
BOOTSTRAP_URI=kafka:29092
CLIENT_ID=sr-1
COMPATIBILITY=BACKWARD
CONNECTIONS_MAX_IDLE_MS=15000
Expand All @@ -14,7 +15,7 @@ FETCH_MIN_BYTES=1
GROUP_ID=group_id8357e932
HOST=127.0.0.1
PORT=8081
REGISTRY_HOST=127.0.0.1
REGISTRY_HOST=karapace-schema-registry
REGISTRY_PORT=8081
REST_AUTHORIZATION=False
LOG_HANDLER=stdout
Expand All @@ -38,8 +39,11 @@ NAME_STRATEGY=topic_name
NAME_STRATEGY_VALIDATION=True
MASTER_ELECTION_STRATEGY=lowest
PROTOBUF_RUNTIME_DIRECTORY=runtime
STATSD_HOST=127.0.0.1
STATSD_HOST=statsd-exporter
STATSD_PORT=8125
KAFKA_SCHEMA_READER_STRICT_MODE=False
KAFKA_RETRIABLE_ERRORS_SILENCED=True
USE_PROTOBUF_FORMATTER=False
REST_BASE_URI=http://karapace-rest-proxy:8082
HTTP_REQUEST_MAX_SIZE=1048576
TAGS='{ "app": "karapace" }'
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ warn_no_return = True
warn_unreachable = True
strict_equality = True

[mypy-karapace.schema_registry_apis]
[mypy-schema_registry.schema_registry_apis]
ignore_errors = True

[mypy-karapace.compatibility.jsonschema.checks]
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ dependencies = [
"zstandard",
"prometheus-client == 0.20.0",
"yarl == 1.12.1",
"opentelemetry-api == 1.28.2",
"opentelemetry-sdk == 1.28.2",
"opentelemetry-instrumentation-fastapi == 0.49b2",
"dependency-injector == 4.43.0",

# Patched dependencies
#
Expand Down Expand Up @@ -105,6 +109,12 @@ typing = [
[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
karapace = ["*.yaml"]

[tool.setuptools_scm]
version_file = "src/karapace/version.py"

Expand Down
Loading

0 comments on commit 6225ae5

Please sign in to comment.