Skip to content

Commit b3b3955

Browse files
committed
Merge pull request #481 from basho/fixes/lrb/bad-resource-base-exception-gh-480
READY: Ensure that BadResource only wraps other exceptions.
2 parents 2c95699 + 2991246 commit b3b3955

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

riak/tests/test_pool.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
from six import PY2
55
from threading import Thread, currentThread
6-
from riak.transports.pool import Pool, BadResource
76
from random import SystemRandom
87
from time import sleep
8+
9+
from riak import RiakError
910
from riak.tests import RUN_POOL
1011
from riak.tests.comparison import Comparison
12+
from riak.transports.pool import Pool, BadResource
1113

1214
if PY2:
1315
from Queue import Queue
@@ -36,6 +38,21 @@ def create_resource(self):
3638
@unittest.skipUnless(RUN_POOL, 'RUN_POOL is 0')
3739
class PoolTest(unittest.TestCase, Comparison):
3840

41+
def test_can_raise_bad_resource(self):
42+
ex_msg = 'exception-message!'
43+
with self.assertRaises(BadResource) as cm:
44+
raise BadResource(ex_msg)
45+
ex = cm.exception
46+
self.assertEqual(ex.args[0], ex_msg)
47+
48+
def test_bad_resource_inner_exception(self):
49+
ex_msg = 'exception-message!'
50+
ex = RiakError(ex_msg)
51+
with self.assertRaises(BadResource) as cm:
52+
raise BadResource(ex)
53+
br_ex = cm.exception
54+
self.assertEqual(br_ex.args[0], ex)
55+
3956
def test_yields_new_object_when_empty(self):
4057
"""
4158
The pool should create new resources as needed.

riak/transports/tcp/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def _recv(self, msglen):
186186
# https://docs.python.org/2/howto/sockets.html#using-a-socket
187187
# https://github.com/basho/riak-python-client/issues/399
188188
if nbytes == 0:
189-
raise BadResource('recv_into returned zero bytes unexpectedly')
189+
ex = RiakError('recv_into returned zero bytes unexpectedly')
190+
raise BadResource(ex)
190191
view = view[nbytes:] # slicing views is cheap
191192
toread -= nbytes
192193
nread += nbytes

0 commit comments

Comments
 (0)