Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Add test and util functions for pending track
Browse files Browse the repository at this point in the history
  • Loading branch information
jc-fireball committed Dec 2, 2015
1 parent 5dff3e7 commit 05186f8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tchannel/tornado/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def __init__(self, connection, tchannel=None, direction=None):

connection.set_close_callback(self._on_close)

@property
def num_out_pendings(self):
return len(self._out_pending_res) + len(self._out_pending_req)

def set_close_callback(self, cb):
"""Specify a function to be called when this connection is closed.
Expand Down
9 changes: 9 additions & 0 deletions tchannel/tornado/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ def go():
go()

return all_done_future


def num_out_pendings(conns):
"""Return the total number of out pending req/res among connections"""
num = 0
for con in conns:
num += con.num_out_pendings

return num
53 changes: 53 additions & 0 deletions tests/tornado/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from tchannel.messages import Types
from tchannel import TChannel
from tchannel.tornado.connection import StreamConnection
from tchannel.tornado.util import num_out_pendings


def dummy_headers():
Expand Down Expand Up @@ -81,3 +82,55 @@ def test_close_callback_is_called():
conn.close()

assert (yield cb_future)


@pytest.mark.gen_test
def test_pending_outgoing():
server = TChannel('server')
server.listen()

@server.raw.register
def hello(request):
return 'hi'

client = TChannel('client')
yield client.raw(
hostport=server.hostport,
body='work',
endpoint='hello',
service='server'
)

assert num_out_pendings(
client._dep_tchannel.peers.get(server.hostport).connections
) == 0

assert num_out_pendings(
server._dep_tchannel.peers.peers[0].connections
) == 0


@pytest.mark.gen_test
def test_pending_outgoing_mock():
server = TChannel('server')
server.listen()

@server.raw.register
def hello(request):
return 'hi'

client = TChannel('client')
yield client.raw(
hostport=server.hostport,
body='work',
endpoint='hello',
service='server'
)

assert num_out_pendings(
client._dep_tchannel.peers.get(server.hostport).connections
) == 0

assert num_out_pendings(
server._dep_tchannel.peers.peers[0].connections
) == 0

0 comments on commit 05186f8

Please sign in to comment.