Skip to content

Commit

Permalink
Add integration tests for generated ServiceServerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Jun 11, 2024
1 parent 2a150ee commit d6ecbc8
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 82 deletions.
149 changes: 78 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

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/[email protected]
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/[email protected]

# 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/[email protected]
# 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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
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

MAX_THREAD_POOL_WORKERS = 10

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()
Expand Down
44 changes: 35 additions & 9 deletions grpc-interface-support/test/integration/test_integration_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ 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):
class TestClientServiceLocator(ServiceLocator):
def get_service_location(self, service_name: str) -> str:
return f"{service_name}@127.0.0.1:1234" # noqa: E231

def get_metadata(self, service_name: Optional[str] = None):
pass

class TestServerServiceLocator(ServiceLocator):
def get_service_location(self, service_name: str) -> str:
return f"{service_name}@anyserver:anyport" # noqa: E231
return "@127.0.0.1:1234" # noqa: E231

def get_metadata(self, service_name: Optional[str] = None):
pass

class TestMiddleware(Middleware):
def __init__(self) -> None:
self.service_locator = TestServiceLocator()
def __init__(self, serviceLocator: ServiceLocator) -> None:
self.service_locator = serviceLocator

async def start(self):
pass
Expand All @@ -73,7 +76,30 @@ async def wait_until_ready(self):
async def stop(self):
pass

middleware = TestMiddleware()
print("============= BUILDING SERVER ===================")
os.chdir(os.environ["SERVICE_SERVER_ROOT"])
assert subprocess.check_call(["velocitas", "init", "-v"]) == 0

from seats_service_sdk.seats_pb2_grpc import SeatsServicer
from seats_service_sdk.SeatsServiceServerFactory import SeatsServiceServerFactory

middleware = TestMiddleware(TestServerServiceLocator())
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(TestClientServiceLocator())
client = SeatsServiceClientFactory.create(middleware)

assert client is not None

0 comments on commit d6ecbc8

Please sign in to comment.