From 1909330971930bf7b5d6588d63256218e087395b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Eckel?= Date: Mon, 16 Jan 2023 12:09:25 +0100 Subject: [PATCH] Simplified unit tests (#294) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adjusted make test * 1st improvments to ease testing * simplified gh actions * adjusted gh action file * removed deps * added sudo to apt calls * removed predefined pytest module definitions * added installing planetmint into the unit test container * give time to the db container * added environment variables to unit-test.yml * removed acceptances tests from test executions Signed-off-by: Jürgen Eckel --- .github/workflows/unit-test-abci.yml | 59 ------------------------ .github/workflows/unit-test-no-abci.yml | 60 ------------------------- .github/workflows/unit-tests.yml | 42 +++++++++++++++++ Makefile | 13 ++++-- pytest.ini | 2 +- tests/test_core.py | 2 +- 6 files changed, 54 insertions(+), 124 deletions(-) delete mode 100644 .github/workflows/unit-test-abci.yml delete mode 100644 .github/workflows/unit-test-no-abci.yml create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/unit-test-abci.yml b/.github/workflows/unit-test-abci.yml deleted file mode 100644 index b31328d..0000000 --- a/.github/workflows/unit-test-abci.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright © 2020 Interplanetary Database Association e.V., -# Planetmint and IPDB software contributors. -# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) -# Code is Apache-2.0 and docs are CC-BY-4.0 - -name: Unit tests - with direct ABCI -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Build container - run: | - docker-compose -f docker-compose.yml build --no-cache --build-arg abci_status=enable planetmint - - - name: Save image - run: docker save -o planetmint.tar planetmint_planetmint - - - name: Upload image - uses: actions/upload-artifact@v3 - with: - name: planetmint-abci - path: planetmint.tar - retention-days: 5 - - - test-with-abci: - runs-on: ubuntu-latest - needs: build - strategy: - matrix: - include: - - db: "Tarantool with ABCI" - host: "tarantool" - port: 3303 - abci: "enabled" - - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Download planetmint - uses: actions/download-artifact@v3 - with: - name: planetmint-abci - - - name: Load planetmint - run: docker load -i planetmint.tar - - - name: Start containers - run: docker-compose -f docker-compose.yml up -d planetmint - - - name: Run tests - run: docker exec planetmint_planetmint_1 pytest -v -m abci diff --git a/.github/workflows/unit-test-no-abci.yml b/.github/workflows/unit-test-no-abci.yml deleted file mode 100644 index 3b9b7a8..0000000 --- a/.github/workflows/unit-test-no-abci.yml +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright © 2020 Interplanetary Database Association e.V., -# Planetmint and IPDB software contributors. -# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) -# Code is Apache-2.0 and docs are CC-BY-4.0 - -name: Unit tests - with Planemint -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Build container - run: | - docker-compose -f docker-compose.yml build --no-cache planetmint - - - name: Save image - run: docker save -o planetmint.tar planetmint_planetmint - - - name: Upload image - uses: actions/upload-artifact@v3 - with: - name: planetmint - path: planetmint.tar - retention-days: 5 - - - test-without-abci: - runs-on: ubuntu-latest - needs: build - strategy: - matrix: - include: - - db: "Tarantool without ABCI" - host: "tarantool" - port: 3303 - - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Download planetmint - uses: actions/download-artifact@v3 - with: - name: planetmint - - - name: Load planetmint - run: docker load -i planetmint.tar - - - name: Start containers - run: docker-compose -f docker-compose.yml up -d bdb - - - name: Run tests - run: docker exec planetmint_planetmint_1 pytest -v --cov=planetmint --cov-report xml:htmlcov/coverage.xml - - - name: Upload Coverage to Codecov - uses: codecov/codecov-action@v3 \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..dcf51ce --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,42 @@ +# Copyright © 2020 Interplanetary Database Association e.V., +# Planetmint and IPDB software contributors. +# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) +# Code is Apache-2.0 and docs are CC-BY-4.0 + +name: Unit tests +on: [push, pull_request] + +jobs: + unified-unit-tests: + runs-on: ubuntu-latest + env: + PLANETMINT_DATABASE_BACKEND: tarantool_db + PLANETMINT_DATABASE_HOST: localhost + PLANETMINT_DATABASE_PORT: 3303 + PLANETMINT_SERVER_BIND: 0.0.0.0:9984 + PLANETMINT_WSSERVER_HOST: 0.0.0.0 + PLANETMINT_WSSERVER_ADVERTISED_HOST: localhost + PLANETMINT_TENDERMINT_HOST: localhost + PLANETMINT_TENDERMINT_PORT: 26657 + + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Prepare OS + run: sudo apt-get update && sudo apt-get install -y git zsh curl tarantool-common vim build-essential cmake + + - name: Get Tendermint + run: wget https://github.com/tendermint/tendermint/releases/download/v0.34.15/tendermint_0.34.15_linux_amd64.tar.gz && tar zxf tendermint_0.34.15_linux_amd64.tar.gz + + - name: Install Planetmint + run: pip install -e '.[dev]' + + + - name: Execute Tests + run: make test diff --git a/Makefile b/Makefile index bf09bbb..56398c8 100644 --- a/Makefile +++ b/Makefile @@ -77,11 +77,18 @@ lint: check-py-deps ## Lint the project format: check-py-deps ## Format the project black -l 119 . -test: check-deps test-unit test-acceptance ## Run unit and acceptance tests +test: check-deps test-unit #test-acceptance ## Run unit and acceptance tests test-unit: check-deps ## Run all tests once or specify a file/test with TEST=tests/file.py::Class::test - @$(DC) up -d bdb - @$(DC) exec planetmint pytest ${TEST} + @$(DC) up -d tarantool + #wget https://github.com/tendermint/tendermint/releases/download/v0.34.15/tendermint_0.34.15_linux_amd64.tar.gz + #tar zxf tendermint_0.34.15_linux_amd64.tar.gz + pytest -m "not abci" + rm -rf ~/.tendermint && ./tendermint init && ./tendermint node --consensus.create_empty_blocks=false --rpc.laddr=tcp://0.0.0.0:26657 --proxy_app=tcp://localhost:26658& + pytest -m abci + @$(DC) down + + test-unit-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again @$(DC) run --rm --no-deps planetmint pytest -f diff --git a/pytest.ini b/pytest.ini index 01b5ef6..423dc14 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,7 +1,7 @@ [pytest] testpaths = tests/ norecursedirs = .* *.egg *.egg-info env* devenv* docs -addopts = -m "not abci" +#addopts = -m "not abci" looponfailroots = planetmint tests asyncio_mode = strict markers = diff --git a/tests/test_core.py b/tests/test_core.py index dc1d5e4..2c2335e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -19,7 +19,7 @@ def config(request, monkeypatch): config = { "database": { "backend": backend, - "host": "tarantool", + "host": "localhost", "port": 3303, "name": "bigchain", "replicaset": "bigchain-rs",