Skip to content

Conversation

Copy link

Copilot AI commented Sep 8, 2025

This PR adds comprehensive integration tests for the gRPC BaseApiClient and its utility functions (call_stub_method(), GrpcStreamBroadcaster) in a minimal and reproducible environment, including authentication and signing interceptors.

What's included

gRPC Service Definition

A minimal "hello world" style gRPC service with both unary and server-streaming methods:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply);
  rpc StreamHellos (HelloRequest) returns (stream HelloReply);
}

Test Infrastructure

  • Test Server: Python gRPC server implementation using grpc.aio with authentication support
  • Test Client: Client subclassing BaseApiClient with proper stub typing and generics
  • Generated Stubs: Python gRPC classes generated from the proto definition

Integration Test Coverage

The tests validate core functionality in real client-server scenarios:

  • Unary RPCs using the call_stub_method() utility function
  • Server-streaming RPCs with proper async iteration patterns
  • GrpcStreamBroadcaster functionality with multiple consumers and event handling
  • Authentication interceptors (API key validation)
  • Signing interceptors (HMAC signing with secrets)
  • Timeout handling throughout all operations for reliability

CI-Friendly Design

  • Mock-based tests for environments without gRPC dependencies
  • Standalone validation tests to verify infrastructure setup
  • Comprehensive documentation with usage examples

Example Usage

# Test client subclassing BaseApiClient
class GreeterClient(BaseApiClient[GreeterStub]):
    def __init__(self, server_url: str, *, auth_key: str | None = None):
        super().__init__(
            server_url=server_url,
            create_stub=lambda channel: GreeterStub(channel),
            auth_key=auth_key,
        )

# Integration test with authentication
async def test_authenticated_call():
    client = GreeterClient("grpc://localhost:50051", auth_key="test-key")
    request = HelloRequest(name="World")
    
    response = await call_stub_method(
        client.stub.SayHello,
        request,
        timeout=5.0,
    )
    
    assert "authenticated" in response.message

This ensures that BaseApiClient subclasses integrate generated stubs correctly, utility functions work in real usage scenarios, and security features (authentication/signing) function as intended.

Fixes #173.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Author

Copilot AI commented Sep 8, 2025

@llucax 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] Add Integration tests Add integration tests for gRPC BaseApiClient and utilities Sep 8, 2025
Copilot AI requested a review from llucax September 8, 2025 09:39
Copilot finished work on behalf of llucax September 8, 2025 09:39
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.

Add Integration tests

2 participants