-
Notifications
You must be signed in to change notification settings - Fork 45
Remove assertion for connection close instead throwing StreamClosedError #291
Changes from 1 commit
42d78c8
6947caa
8d1dfd9
30c4d72
ab0c20a
4012b26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
from tchannel.errors import NetworkError | ||
from tchannel.errors import BadRequestError | ||
from tchannel import TChannel | ||
from tchannel.event import EventHook | ||
from tchannel.tornado.connection import StreamConnection | ||
from tests.util import big_arg | ||
|
||
|
@@ -109,3 +110,24 @@ def test_endpoint_not_found(mock_server): | |
endpoint='fooo', | ||
hostport=mock_server.hostport, | ||
) | ||
|
||
|
||
@pytest.mark.gen_test | ||
def test_connection_close(mock_server): | ||
tchannel = TChannel(name='test') | ||
|
||
class TestHook(EventHook): | ||
def before_send_request(self, request): | ||
# close the connection | ||
peer = tchannel._dep_tchannel.peers.get(mock_server.hostport) | ||
peer.close() | ||
peer.connections[0].closed = True | ||
|
||
tchannel.hooks.register(TestHook()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you just call close right here before making the call instead of using the hook? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I call close, then we make a call, we will choose peer and rebuilt a connection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant what if you stop the server here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the way iostream calls the callback method is
from the last line, we see the callback won't be called immediately, there is some delay. That's why even if I stop the server, the call back is triggered later. for testing purpose: I manually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not the problem I'm trying to solve here. I'm trying to solve the hook being used to close the connection. Why not,
That will tell the server to immediately stop listening for new incoming connections, so when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, just to confirm: Is this test just trying to verify that we raise a |
||
|
||
with pytest.raises(NetworkError): | ||
yield tchannel.raw( | ||
service='test-service', | ||
hostport=mock_server.hostport, | ||
endpoint='testg', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused here. Are you trying to re-raise the
StreamClosedError
you caught or do you want the newNetworkError
to be raised?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is will be raised again since we have a try catch from the caller to tell whether we should retry based on the exception or not.
This part will be refined in this task: #285