util.failover: re-raise exceptions on failure
This commit is contained in:
parent
21b09a7451
commit
cba7816caf
2 changed files with 19 additions and 13 deletions
|
@ -2,6 +2,9 @@ import pytest
|
|||
|
||||
from util.failover import failover, FailoverException
|
||||
|
||||
class FinishedException(Exception):
|
||||
""" Exception raised at the end of every iteration to force failover. """
|
||||
|
||||
|
||||
class Counter(object):
|
||||
""" Wraps a counter in an object so that it'll be passed by reference. """
|
||||
|
@ -18,7 +21,7 @@ def my_failover_func(i, should_raise=None):
|
|||
i.increment()
|
||||
if should_raise is not None:
|
||||
raise should_raise()
|
||||
raise FailoverException(None, 'incrementing')
|
||||
raise FailoverException(FinishedException())
|
||||
|
||||
|
||||
@pytest.mark.parametrize('stop_on,exception', [
|
||||
|
@ -40,5 +43,6 @@ def test_readonly_failover(stop_on, exception):
|
|||
with pytest.raises(exception):
|
||||
my_failover_func(*arg_sets)
|
||||
else:
|
||||
my_failover_func(*arg_sets)
|
||||
assert counter.calls == stop_on
|
||||
with pytest.raises(FinishedException):
|
||||
my_failover_func(*arg_sets)
|
||||
assert counter.calls == stop_on
|
||||
|
|
Reference in a new issue