Skip to content

Commit

Permalink
Merge pull request #481 from basho/fixes/lrb/bad-resource-base-except…
Browse files Browse the repository at this point in the history
…ion-gh-480

READY: Ensure that BadResource only wraps other exceptions.
  • Loading branch information
lukebakken committed Jun 1, 2016
2 parents 2c95699 + 2991246 commit b3b3955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion riak/tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from six import PY2
from threading import Thread, currentThread
from riak.transports.pool import Pool, BadResource
from random import SystemRandom
from time import sleep

from riak import RiakError
from riak.tests import RUN_POOL
from riak.tests.comparison import Comparison
from riak.transports.pool import Pool, BadResource

if PY2:
from Queue import Queue
Expand Down Expand Up @@ -36,6 +38,21 @@ def create_resource(self):
@unittest.skipUnless(RUN_POOL, 'RUN_POOL is 0')
class PoolTest(unittest.TestCase, Comparison):

def test_can_raise_bad_resource(self):
ex_msg = 'exception-message!'
with self.assertRaises(BadResource) as cm:
raise BadResource(ex_msg)
ex = cm.exception
self.assertEqual(ex.args[0], ex_msg)

def test_bad_resource_inner_exception(self):
ex_msg = 'exception-message!'
ex = RiakError(ex_msg)
with self.assertRaises(BadResource) as cm:
raise BadResource(ex)
br_ex = cm.exception
self.assertEqual(br_ex.args[0], ex)

def test_yields_new_object_when_empty(self):
"""
The pool should create new resources as needed.
Expand Down
3 changes: 2 additions & 1 deletion riak/transports/tcp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def _recv(self, msglen):
# https://docs.python.org/2/howto/sockets.html#using-a-socket
# https://github.com/basho/riak-python-client/issues/399
if nbytes == 0:
raise BadResource('recv_into returned zero bytes unexpectedly')
ex = RiakError('recv_into returned zero bytes unexpectedly')
raise BadResource(ex)
view = view[nbytes:] # slicing views is cheap
toread -= nbytes
nread += nbytes
Expand Down

0 comments on commit b3b3955

Please sign in to comment.