Skip to content

Commit

Permalink
chore(grpc-asyncio): add live broker smoketest
Browse files Browse the repository at this point in the history
  • Loading branch information
joekickass committed Sep 13, 2024
1 parent 61bddac commit fa7415c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
17 changes: 8 additions & 9 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Published to PyPI on [https://pypi.org/project/remotivelabs-broker/](https://pyp
Prerequisites:

```bash
# Install poetry (and optionally poe plugin)
# Install poetry (and optionally poe plugin to simplify poetry command execution)
pipx install poetry
poetry self add 'poethepoet[poetry_plugin]'
```
Expand All @@ -25,14 +25,14 @@ poetry install
# Build the library (output in dist/)
poetry build

# test local (local test does not require a running broker)
poetry poe test-local
# Check (test, lint, check types)
poetry poe check

# test server (server test requires a running broker)
poetry poe test-server
# run standard test suite
poetry run pytest

# test all
poetry poe test
# run tests against running broker
poetry run pytest -m server --broker <broker url>
```

If you need to (re)generate protobuf stubs, see [Building](#building).
Expand All @@ -42,8 +42,7 @@ If you need to (re)generate protobuf stubs, see [Building](#building).
Building the complete package, including protobuf stubs and documentation, is done using a docker container:

```bash
cd python/remotivelabs-broker
./docker-build.sh
./python/remotivelabs-broker/docker-build.sh
```

## Versioning
Expand Down
16 changes: 16 additions & 0 deletions python/remotivelabs-broker/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--broker",
action="store",
default="http://localhost:50051",
type=str,
help="Broker URI to run test against.",
)


@pytest.fixture
def broker_url(request):
return request.config.getoption("--broker")
9 changes: 3 additions & 6 deletions python/remotivelabs-broker/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ json-schema-for-humans = "^1.0"
[tool.poe.tasks]
test-server = "pytest -m server --cov=remotivelabs.broker"
test = "pytest --cov=remotivelabs.broker"
format = [{ cmd = "ruff check --select I --fix" }, { cmd = "ruff format" }]
format-check = [
{ cmd = "ruff check --select I" },
{ cmd = "ruff format --check --diff" },
]
format = [{ cmd = "ruff check --fix ." }, { cmd = "ruff format ." }]
lint = [{ cmd = "ruff check ." }, { cmd = "ruff format --check --diff ." }]
mypy-check = [{ cmd = "mypy remotivelabs/broker" }, { cmd = "mypy tests" }]
check = ["test", "format-check", "mypy-check"]
check = ["test", "lint", "mypy-check"]

[tool.ruff]
line-length = 140
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
from __future__ import annotations

import logging

import pytest

import remotivelabs.broker as br
import remotivelabs.broker.sync as br_sync

# Warning these tests require a RemotiveBroker up and running
# server address:
_SERVER_URL = "http://127.0.0.1:50051"
_SERVER_APIKEY = None


class Connection:
def __init__(self):
self.channel = br_sync.create_channel(_SERVER_URL, _SERVER_APIKEY)
self.network_stub = br.network_api_pb2_grpc.NetworkServiceStub(self.channel)
def __init__(self, url: str, api_key: str | None = None):
self.channel = br_sync.create_channel(url, api_key)
self.system_stub = br.system_api_pb2_grpc.SystemServiceStub(self.channel)


# Setup broker with predefined settings
@pytest.fixture(name="broker_connection")
def fixture_broker_connection():
return Connection()
def fixture_broker_connection(broker_url):
return Connection(broker_url)


# Setup broker configured for testing
@pytest.fixture(name="broker_configured")
def fixture_broker_configured(broker_connection):
br_sync.upload_folder(broker_connection.system_stub, "tests/fixtures/configs/udp")
Expand Down Expand Up @@ -52,6 +46,7 @@ def test_meta_fields(broker_configured):
assert meta_speed.getSize() == 16
assert meta_speed.getIsRaw() is False
assert meta_parent.getIsRaw() is True

assert meta_speed.getFactor() == 1.0
assert meta_speed.getOffset() == 0.0
assert meta_speed.getSenders() == ["ECUA"]
Expand Down

0 comments on commit fa7415c

Please sign in to comment.