diff options
author | Wouter Bolsterlee <uws@xs4all.nl> | 2013-06-04 21:59:26 +0200 |
---|---|---|
committer | Wouter Bolsterlee <uws@xs4all.nl> | 2013-06-04 21:59:26 +0200 |
commit | 615e2ebf2b2fcca1b4aabc256deccba3f615761f (patch) | |
tree | 229f9966b903424577f762752e866ea330cef4f3 /tests | |
parent | 48b33d789222a07e7b463aca01a7e06f7b59bab8 (diff) | |
download | happybase-615e2ebf2b2fcca1b4aabc256deccba3f615761f.tar.gz |
Rewrite connection pool exception handling
The connection pool now uses a much simpler try/except/finally block in
the context manager function to detect network/Thrift errors. The pool
will now only refreshes connections when Thrift or socket errors occur,
and will not react to unrelated application errors anymore.
With this approach, the _ClientProxy hack is not needed anymore, so it
has been completely eliminated.
See issue #25.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_api.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/test_api.py b/tests/test_api.py index 9ecaabc..28a4623 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -455,6 +455,8 @@ def test_connection_pool_construction(): def test_connection_pool(): + from thrift.transport.TTransport import TTransportException + def run(): name = threading.current_thread().name print "Thread %s starting" % name @@ -464,15 +466,24 @@ def test_connection_pool(): with pool.connection() as another_connection: assert connection is another_connection + # Fake an exception once in a while + if random.random() < .001: + connection.transport.close() + raise TTransportException("Fake transport exception") + for i in xrange(100): with pool.connection() as connection: connection.tables() - # Fake an exception once in a while - if random.random() < .001: - connection._tainted = True + try: + inner_function() + except TTransportException: + # This error should have been picked up by the + # connection pool, and the connection should have + # been replaced by a fresh one + pass - inner_function() + connection.tables() print "Thread %s done" % name |