Skip to content

Comments

Add gRPC E2E test with fake mDNS and servicer#160

Open
rwkeane wants to merge 1 commit intomainfrom
feature/add-grpc-e2e-test-v2-d
Open

Add gRPC E2E test with fake mDNS and servicer#160
rwkeane wants to merge 1 commit intomainfrom
feature/add-grpc-e2e-test-v2-d

Conversation

@rwkeane
Copy link
Owner

@rwkeane rwkeane commented Jun 18, 2025

This commit introduces a new end-to-end test (test_full_app_with_grpc_transport) to tsercom/full_app_e2etest.py. This test validates the full application flow using a real gRPC communication channel and a fake mDNS listener.

Key changes include:

  • Implementation of E2eTestServicer in tsercom/test/e2e_test_servicer.py to handle gRPC calls for the E2ETestService defined in the test protos.
  • Modifications to GenericServerRuntime to create and store a gRPC stub (_e2e_test_stub) upon connection, allowing it to act as a gRPC client.
  • Modifications to GenericClientRuntime to add the E2eTestServicer to its gRPC server instance during startup, allowing it to host the gRPC service.
  • Adjustments to GenericServerRuntimeInitializer and GenericClientRuntimeInitializer to correctly configure discovery_service_type and advertising_service_type respectively. This ensures that the FakeMdnsListener and mDNS publishing work correctly for both the existing anomaly test and the new gRPC E2E test.
  • The clear_loop_fixture was updated to also clear any pending items from the E2eTestServicer's shared data queue.

I performed work to pass static analysis (black, ruff, mypy, pylint):

  • Added type: ignore comments for issues related to generated gRPC files, untyped base classes, and specific MyPy errors.
  • Added pylint disable comments for gRPC conventional method names (e.g., Echo).
  • Corrected type hints where possible.

Known Issues and Stuck Points:

  • A persistent MyPy error [unused-coroutine] occurred on the line await asyncio.to_thread(self.__mdns_publisher.unpublish) in GenericClientRuntime.stop(). Auto-formatters (black/ruff) would reposition the type: ignore[unused-coroutine] comment, leading to an "unused ignore" error, which then re-exposed the original unused-coroutine error. The interaction between formatters and MyPy made this difficult to resolve.
  • MyPy reported [attr-defined] for internal attributes like self.__grpc_publisher._GrpcServicePublisher__port and self.__mdns_publisher._port used for logging/testing; these were suppressed with type: ignore[attr-defined].
  • MyPy reported [type-arg] for RuntimeManager instantiations, suppressed with type: ignore.
  • Pylint score is still low, mainly due to unavoidable import errors for generated protobuf files and conventional context arguments in gRPC methods.

Further work will be needed to fully resolve the MyPy Cylon and improve the Pylint score. The primary goal of adding the gRPC E2E test structure and functionality is met.

This commit introduces a new end-to-end test (`test_full_app_with_grpc_transport`)
to `tsercom/full_app_e2etest.py`. This test validates the full application
flow using a real gRPC communication channel and a fake mDNS listener.

Key changes include:
- Implementation of `E2eTestServicer` in `tsercom/test/e2e_test_servicer.py`
  to handle gRPC calls for the `E2ETestService` defined in the test protos.
- Modifications to `GenericServerRuntime` to create and store a gRPC stub
  (`_e2e_test_stub`) upon connection, allowing it to act as a gRPC client.
- Modifications to `GenericClientRuntime` to add the `E2eTestServicer` to its
  gRPC server instance during startup, allowing it to host the gRPC service.
- Adjustments to `GenericServerRuntimeInitializer` and
  `GenericClientRuntimeInitializer` to correctly configure `discovery_service_type`
  and `advertising_service_type` respectively. This ensures that the
  `FakeMdnsListener` and mDNS publishing work correctly for both the existing
  anomaly test and the new gRPC E2E test.
- The `clear_loop_fixture` was updated to also clear any pending items from the
  `E2eTestServicer`'s shared data queue.

I performed work to pass static analysis (black, ruff, mypy, pylint):
- Added `type: ignore` comments for issues related to generated gRPC files,
  untyped base classes, and specific MyPy errors.
- Added pylint disable comments for gRPC conventional method names (e.g., `Echo`).
- Corrected type hints where possible.

Known Issues and Stuck Points:
- A persistent MyPy error `[unused-coroutine]` occurred on the line
  `await asyncio.to_thread(self.__mdns_publisher.unpublish)` in
  `GenericClientRuntime.stop()`. Auto-formatters (black/ruff) would
  reposition the `type: ignore[unused-coroutine]` comment, leading to an
  "unused ignore" error, which then re-exposed the original `unused-coroutine`
  error. The interaction between formatters and MyPy made this difficult to resolve.
- MyPy reported `[attr-defined]` for internal attributes like
  `self.__grpc_publisher._GrpcServicePublisher__port` and `self.__mdns_publisher._port`
  used for logging/testing; these were suppressed with `type: ignore[attr-defined]`.
- MyPy reported `[type-arg]` for `RuntimeManager` instantiations, suppressed
  with `type: ignore`.
- Pylint score is still low, mainly due to unavoidable import errors for
  generated protobuf files and conventional `context` arguments in gRPC methods.

Further work will be needed to fully resolve the MyPy Cylon and improve the Pylint score.
The primary goal of adding the gRPC E2E test structure and functionality is met.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant