enhance connection observer tests
set_result() after set_exception() raises ResultAlreadySet
@@ -243,7 +243,7 @@ def test_can_retrieve_connection_observer_result_after_setting_result(do_nothing
assert connection_observer.result() == 14361
-def test_setting_result_multiple_times_raises_CommandResultAlreadySet(do_nothing_connection_observer__for_major_base_class):
+def test_setting_result_multiple_times_raises_ResultAlreadySet(do_nothing_connection_observer__for_major_base_class):
connection_observer = do_nothing_connection_observer__for_major_base_class
from moler.exceptions import ResultAlreadySet
# We start feeding connection-observer with data coming from connection
@@ -257,6 +257,20 @@ def test_setting_result_multiple_times_raises_CommandResultAlreadySet(do_nothing
assert str(error.value) == 'for {}'.format(str(connection_observer))
+def test_setting_result_after_set_exception_raises_ResultAlreadySet(do_nothing_connection_observer__for_major_base_class):
+ connection_observer = do_nothing_connection_observer__for_major_base_class
+ from moler.exceptions import ResultAlreadySet
+ # set_exception() and set_result() may come from different threads (runner/external-io) - so,
+ # we must be secured against race
+ exc = Exception("exception in runner")
+ connection_observer.set_exception(exc)
+ with pytest.raises(ResultAlreadySet) as error:
+ connection_observer.set_result(78990) # trial to overwrite exception with the result
+
+ assert error.value.connection_observer == connection_observer
+ assert str(error.value) == 'for {}'.format(str(connection_observer))
+
+
def test_calling_result_on_cancelled_connection_observer_raises_NoResultSinceCommandCancelled(do_nothing_connection_observer__for_major_base_class):
connection_observer = do_nothing_connection_observer__for_major_base_class
from moler.exceptions import NoResultSinceCancelCalled
