|
10 | 10 |
|
11 | 11 | import socket |
12 | 12 | import pytest |
| 13 | +from twisted.internet import reactor |
| 14 | +from twisted.web import server |
13 | 15 |
|
14 | 16 | from hyperframe.frame import Frame |
15 | | -from werkzeug.datastructures import Headers |
| 17 | +from rolo import Router |
| 18 | +from rolo.gateway import Gateway |
| 19 | +from localstack.utils.net import get_free_tcp_port |
16 | 20 | from localstack_extensions.utils.docker import ProxiedDockerContainerExtension |
17 | 21 |
|
18 | | - |
19 | 22 | GRPCBIN_IMAGE = "moul/grpcbin" |
20 | 23 | GRPCBIN_INSECURE_PORT = 9000 # HTTP/2 without TLS |
21 | 24 | GRPCBIN_SECURE_PORT = 9001 # HTTP/2 with TLS |
@@ -55,37 +58,58 @@ def _tcp_health_check(): |
55 | 58 | health_check_fn=_tcp_health_check, |
56 | 59 | ) |
57 | 60 |
|
58 | | - def http2_request_matcher(self, headers: Headers) -> bool: |
59 | | - """ |
60 | | - gRPC services use direct TCP connections, not HTTP gateway routing. |
61 | | - This method is not used in these tests but is required by the base class. |
62 | | - """ |
63 | | - return False |
64 | | - |
65 | 61 |
|
66 | 62 | @pytest.fixture(scope="session") |
67 | | -def grpcbin_extension(): |
| 63 | +def grpcbin_extension_server(): |
68 | 64 | """ |
69 | | - Start grpcbin using ProxiedDockerContainerExtension. |
| 65 | + Start grpcbin using ProxiedDockerContainerExtension with a test gateway server. |
70 | 66 |
|
71 | | - This tests the Docker container management capabilities while providing |
72 | | - a realistic gRPC/HTTP2 test service for integration tests. |
| 67 | + This tests the Docker container management and proxy capabilities by: |
| 68 | + 1. Starting the grpcbin container via the extension |
| 69 | + 2. Setting up a Gateway with the extension's routes |
| 70 | + 3. Serving the Gateway on a test port via Twisted |
| 71 | + 4. Returning server info for end-to-end testing |
73 | 72 | """ |
74 | 73 | extension = GrpcbinExtension() |
75 | 74 |
|
76 | | - # Start the container using the extension infrastructure |
77 | | - extension.start_container() |
| 75 | + # Create router and update with extension routes |
| 76 | + # This will start the grpcbin container |
| 77 | + router = Router() |
| 78 | + extension.update_gateway_routes(router) |
| 79 | + |
| 80 | + # Create a Gateway with the router |
| 81 | + gateway = Gateway(router) |
| 82 | + |
| 83 | + # Start twisted web server on a test port |
| 84 | + test_port = get_free_tcp_port() |
| 85 | + site = server.Site(gateway) |
| 86 | + listener = reactor.listenTCP(test_port, site) |
78 | 87 |
|
79 | | - yield extension |
| 88 | + # Return server information for tests |
| 89 | + server_info = { |
| 90 | + "port": test_port, |
| 91 | + "url": f"http://localhost:{test_port}", |
| 92 | + "extension": extension, |
| 93 | + "listener": listener, |
| 94 | + } |
| 95 | + |
| 96 | + yield server_info |
80 | 97 |
|
81 | 98 | # Cleanup |
| 99 | + listener.stopListening() |
82 | 100 | extension.on_platform_shutdown() |
83 | 101 |
|
84 | 102 |
|
| 103 | +@pytest.fixture(scope="session") |
| 104 | +def grpcbin_extension(grpcbin_extension_server): |
| 105 | + """Return the extension instance from the server fixture.""" |
| 106 | + return grpcbin_extension_server["extension"] |
| 107 | + |
| 108 | + |
85 | 109 | @pytest.fixture |
86 | | -def grpcbin_host(grpcbin_extension): |
| 110 | +def grpcbin_host(grpcbin_extension_server): |
87 | 111 | """Return the host address for the grpcbin container.""" |
88 | | - return grpcbin_extension.container_host |
| 112 | + return grpcbin_extension_server["extension"].container_host |
89 | 113 |
|
90 | 114 |
|
91 | 115 | @pytest.fixture |
|
0 commit comments