From d2264a504e443b19a25f815d94ffc5da22831c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Mon, 10 Jun 2024 13:24:13 +0200 Subject: [PATCH] Add integration tests for the generated ServiceServerFactory --- .github/workflows/ci.yml | 149 +++++++++--------- .../python/ServiceNameServiceServerFactory.py | 6 +- .../integration/test_integration_python.py | 29 +++- 3 files changed, 107 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6f5ad70..2f86a841 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,81 +22,81 @@ on: push: # Run only on branches/commits and not tags branches: - - main + - feature-100 pull_request: branches: - main jobs: - lint-job: - name: "Run linters" - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install deps - run: | - pip install mypy - pip install types-requests - - - name: Run Linters - uses: pre-commit/action@v3.0.0 - - unit-test: - name: "Run unit tests" - runs-on: ubuntu-22.04 - container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.3 - strategy: - matrix: - component: ["_shared", "setup", "grpc-interface-support", "vehicle-model-lifecycle", "sdk-installer", "build-system/cpp-cmake-conan"] - fail-fast: false - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install required packages - run: | - if [ -e "${{ matrix.component }}/requirements.txt" ]; then - pip install -r ${{ matrix.component }}/requirements.txt - fi - - if [ -e "${{ matrix.component }}/test/requirements.txt" ]; then - pip install -r ${{ matrix.component }}/test/requirements.txt - fi - - - name: unit test - shell: bash - run: | - pytest --override-ini junit_family=xunit1 \ - --junit-xml=./results/UnitTest/${{ matrix.component }}/junit.xml \ - --cov . \ - --cov-report=xml:results/CodeCoverage/${{ matrix.component }}/cobertura-coverage.xml \ - --cov-branch \ - ./${{ matrix.component }}/test/unit - - - name: Publish Test Report - uses: mikepenz/action-junit-report@v3 - if: always() - with: - report_paths: ./results/UnitTest/${{ matrix.component }}/junit.xml - summary: true - update_check: true - annotate_only: true - - - uses: irongut/CodeCoverageSummary@v1.3.0 - with: - filename: results/CodeCoverage/${{ matrix.component }}/cobertura-coverage.xml - badge: true - format: markdown - hide_complexity: true - indicators: true - output: both - - - run: | - cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY + # lint-job: + # name: "Run linters" + # runs-on: ubuntu-latest + + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Install deps + # run: | + # pip install mypy + # pip install types-requests + + # - name: Run Linters + # uses: pre-commit/action@v3.0.0 + + # unit-test: + # name: "Run unit tests" + # runs-on: ubuntu-22.04 + # container: ghcr.io/eclipse-velocitas/devcontainer-base-images/python:v0.3 + # strategy: + # matrix: + # component: ["_shared", "setup", "grpc-interface-support", "vehicle-model-lifecycle", "sdk-installer", "build-system/cpp-cmake-conan"] + # fail-fast: false + + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Install required packages + # run: | + # if [ -e "${{ matrix.component }}/requirements.txt" ]; then + # pip install -r ${{ matrix.component }}/requirements.txt + # fi + + # if [ -e "${{ matrix.component }}/test/requirements.txt" ]; then + # pip install -r ${{ matrix.component }}/test/requirements.txt + # fi + + # - name: unit test + # shell: bash + # run: | + # pytest --override-ini junit_family=xunit1 \ + # --junit-xml=./results/UnitTest/${{ matrix.component }}/junit.xml \ + # --cov . \ + # --cov-report=xml:results/CodeCoverage/${{ matrix.component }}/cobertura-coverage.xml \ + # --cov-branch \ + # ./${{ matrix.component }}/test/unit + + # - name: Publish Test Report + # uses: mikepenz/action-junit-report@v3 + # if: always() + # with: + # report_paths: ./results/UnitTest/${{ matrix.component }}/junit.xml + # summary: true + # update_check: true + # annotate_only: true + + # - uses: irongut/CodeCoverageSummary@v1.3.0 + # with: + # filename: results/CodeCoverage/${{ matrix.component }}/cobertura-coverage.xml + # badge: true + # format: markdown + # hide_complexity: true + # indicators: true + # output: both + + # - run: | + # cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY run-integration-tests: name: Run Integration Test @@ -105,7 +105,14 @@ jobs: strategy: matrix: language: ["python", "cpp"] - component: ["setup", "grpc-interface-support", "vehicle-model-lifecycle", "sdk-installer", "build-system/cpp-cmake-conan"] + component: + [ + "setup", + "grpc-interface-support", + "vehicle-model-lifecycle", + "sdk-installer", + "build-system/cpp-cmake-conan", + ] fail-fast: false steps: diff --git a/grpc-interface-support/data/templates/python/ServiceNameServiceServerFactory.py b/grpc-interface-support/data/templates/python/ServiceNameServiceServerFactory.py index 0531dcda..601a609a 100644 --- a/grpc-interface-support/data/templates/python/ServiceNameServiceServerFactory.py +++ b/grpc-interface-support/data/templates/python/ServiceNameServiceServerFactory.py @@ -16,7 +16,7 @@ import concurrent.futures from ${{ service_name_lower }}_service_sdk.${{ service_name_lower }}_pb2_grpc import ( - ${{ service_name }}Stub, + ${{ service_name }}Servicer, add_${{ service_name }}Servicer_to_server ) from velocitas_sdk.base import Middleware @@ -24,10 +24,12 @@ class ${{ service_name_camel_case }}ServiceServerFactory: @staticmethod - def create(middleware: Middleware) -> grpc.Server: + def create(middleware: Middleware, servicer: ${{ service_name }}Servicer) -> grpc.Server: address = middleware.service_locator.get_service_location("${{ service_name }}") server = grpc.server(concurrent.futures.ThreadPoolExecutor(MAX_THREAD_POOL_WORKERS)) server.add_insecure_port(address) + + add_${{ service_name }}Servicer_to_server(servicer, server) server.start() server.wait_for_termination() diff --git a/grpc-interface-support/test/integration/test_integration_python.py b/grpc-interface-support/test/integration/test_integration_python.py index d5c99847..d8578009 100644 --- a/grpc-interface-support/test/integration/test_integration_python.py +++ b/grpc-interface-support/test/integration/test_integration_python.py @@ -47,10 +47,6 @@ def test_python_package_is_generated(): def test_pip_package_is_usable(): - os.chdir(os.environ["SERVICE_CLIENT_ROOT"]) - assert subprocess.check_call(["velocitas", "init", "-v"]) == 0 - - from seats_service_sdk.SeatsServiceClientFactory import SeatsServiceClientFactory from velocitas_sdk.base import Middleware, ServiceLocator class TestServiceLocator(ServiceLocator): @@ -73,6 +69,31 @@ async def wait_until_ready(self): async def stop(self): pass + print("============= BUILDING SERVER ===================") + os.chdir(os.environ["SERVICE_SERVER_ROOT"]) + assert subprocess.check_call(["velocitas", "init", "-v"]) == 0 + + from seats_service_sdk.SeatsServiceServerFactory import ( + SeatsServiceServerFactory, + SeatsServicer, + ) + + middleware = TestMiddleware() + servicer = SeatsServicer() + + server = SeatsServiceServerFactory.create( + middleware, + servicer, + ) + + assert server is not None + + print("============= BUILDING CLIENT ===================") + os.chdir(os.environ["SERVICE_CLIENT_ROOT"]) + assert subprocess.check_call(["velocitas", "init", "-v"]) == 0 + + from seats_service_sdk.SeatsServiceClientFactory import SeatsServiceClientFactory + middleware = TestMiddleware() client = SeatsServiceClientFactory.create(middleware)