File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 22from concurrent .futures import Future
33from dataclasses import dataclass
44from queue import Queue
5+ from unittest import mock
56
67import pytest
78
@@ -76,6 +77,21 @@ def test_correlation_id(publisher: EventPublisher[MyEvent]) -> None:
7677 assert f .result (timeout = _TIMEOUT ) == correlation_id
7778
7879
80+ def test_callback_exceptions_are_contained (publisher : EventPublisher [MyEvent ]):
81+ event = MyEvent ("foo" )
82+ c_id = "bar"
83+
84+ # First call should raise exception, next should be fine
85+ handler = mock .Mock (side_effect = [ValueError ("Bad Event" ), ()])
86+ publisher .subscribe (handler )
87+ publisher .subscribe (handler )
88+
89+ publisher .publish (event , c_id )
90+
91+ # Both handlers should be called and the exception should not be raised from publish
92+ handler .assert_has_calls ([mock .call (event , c_id ), mock .call (event , c_id )])
93+
94+
7995def _drain (queue : Queue ) -> Iterable :
8096 while not queue .empty ():
8197 yield queue .get_nowait ()
You can’t perform that action at this time.
0 commit comments