Skip to content

Commit

Permalink
Merge pull request #60 from stephenc-pace/fix/lazy-channel
Browse files Browse the repository at this point in the history
use a method rather than property
  • Loading branch information
timbu authored Oct 3, 2023
2 parents a557833 + 04cbe32 commit af24427
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 1 addition & 2 deletions nameko_grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def stop(self):
self._channel.stop()
self._channel = None

@property
def channel(self):
if self._channel is None:
self._start_channel()
Expand All @@ -185,7 +184,7 @@ def timeout(self, send_stream, response_stream, deadline):
time.sleep(0.001)

def invoke(self, request_headers, request, timeout):
send_stream, response_stream = self.channel.send_request(request_headers)
send_stream, response_stream = self.channel().send_request(request_headers)
if timeout:
self.spawn_thread(
target=self.timeout,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name="nameko-grpc",
version="1.4.0rc1",
version="1.4.0rc2",
description="Nameko gRPC extensions",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down
2 changes: 2 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def make(
proto_name=None,
compression_algorithm="none",
compression_level="high",
lazy_startup=False,
):
if proto_name is None:
proto_name = service_name
Expand All @@ -414,6 +415,7 @@ class Service:
stub_cls,
compression_algorithm=compression_algorithm,
compression_level=compression_level,
lazy_startup=lazy_startup,
)

@dummy
Expand Down
14 changes: 14 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,17 @@ def test_lazy_client_does_not_connect_on_start(
def test_nonlazy_client_connects_on_start(self, start_nameko_client, protobufs):
with pytest.raises(ConnectionRefusedError):
start_nameko_client("example", lazy_startup=False)

def test_lazy_client_with_with_dependency_provider(
self, start_dependency_provider, protobufs, start_grpc_server
):
client = start_dependency_provider("example", lazy_startup=True)

with pytest.raises(ConnectionRefusedError):
client.unary_unary(protobufs.ExampleRequest(value="A"))

start_grpc_server("example")

# After starting the server, should now work
response = client.unary_unary(protobufs.ExampleRequest(value="A"))
assert response.message == "A"

0 comments on commit af24427

Please sign in to comment.