-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dan-hipschman-od/support-streaming
Support streaming RPCs
- Loading branch information
Showing
9 changed files
with
191 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/.idea/ | ||
/.nox/ | ||
/.venv/ | ||
/.vscode/ | ||
/coverage.xml | ||
/dist/ | ||
/docs/_build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Test cases for streaming RPCs.""" | ||
|
||
import grpc | ||
import pytest | ||
|
||
from grpc_interceptor import ServerInterceptor | ||
from grpc_interceptor.testing import dummy_client, DummyRequest | ||
|
||
|
||
class StreamingInterceptor(ServerInterceptor): | ||
"""A test interceptor that streams.""" | ||
|
||
def intercept(self, method, request, context, method_name): | ||
"""Doesn't do anything; just make sure we handle streaming RPCs.""" | ||
return method(request, context) | ||
|
||
|
||
@pytest.fixture | ||
def interceptors(): | ||
"""The interceptor chain for this test suite.""" | ||
intr = StreamingInterceptor() | ||
return [intr] | ||
|
||
|
||
def test_client_streaming(interceptors): | ||
"""Client streaming should work.""" | ||
special_cases = {"error": lambda r, c: 1 / 0} | ||
with dummy_client(special_cases=special_cases, interceptors=interceptors) as client: | ||
inputs = ["foo", "bar"] | ||
input_iter = (DummyRequest(input=input) for input in inputs) | ||
assert client.ExecuteClientStream(input_iter).output == "foobar" | ||
|
||
inputs = ["foo", "error"] | ||
input_iter = (DummyRequest(input=input) for input in inputs) | ||
with pytest.raises(grpc.RpcError): | ||
client.ExecuteClientStream(input_iter) | ||
|
||
|
||
def test_server_streaming(interceptors): | ||
"""Server streaming should work.""" | ||
with dummy_client(special_cases={}, interceptors=interceptors) as client: | ||
output = [ | ||
r.output for r in client.ExecuteServerStream(DummyRequest(input="foo")) | ||
] | ||
assert output == ["f", "o", "o"] | ||
|
||
|
||
def test_client_server_streaming(interceptors): | ||
"""Bidirectional streaming should work.""" | ||
with dummy_client(special_cases={}, interceptors=interceptors) as client: | ||
inputs = ["foo", "bar"] | ||
input_iter = (DummyRequest(input=input) for input in inputs) | ||
response = client.ExecuteClientServerStream(input_iter) | ||
assert [r.output for r in response] == inputs |