-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIU-322: Log exceptions during async InputFiredAppDrop execution
Add test to ensure it is only exceptions outside of normal execution that get caught and logged here.
- Loading branch information
1 parent
0481797
commit b71eae0
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import threading | ||
from dlg.drop import InputFiredAppDROP | ||
from dlg.event import Event, EventHandler | ||
import pytest | ||
|
||
|
||
class MockThrowingDrop(InputFiredAppDROP): | ||
def run(): | ||
raise RuntimeError("Drop throw") | ||
|
||
|
||
class MockThrowingHandler(EventHandler): | ||
def handleEvent(self, e: Event) -> None: | ||
raise RuntimeError("Handler throw") | ||
|
||
|
||
def test_async_execute_catches_and_logs_unexpected_exception( | ||
caplog: pytest.LogCaptureFixture, | ||
): | ||
drop = MockThrowingDrop("t", "t", n_effective_inputs=1) | ||
handler = MockThrowingHandler() | ||
drop.subscribe(handler) | ||
|
||
thread = drop.async_execute() | ||
assert isinstance(thread, threading.Thread) | ||
thread.join() | ||
|
||
assert "Handler throw" in caplog.text | ||
# execute should handle exceptions in the run method | ||
assert "Drop throw" not in caplog.text | ||
|
||
|
||
def test_execute_propogates_unexpected_exception(): | ||
drop = MockThrowingDrop("t", "t", n_effective_inputs=1) | ||
handler = MockThrowingHandler() | ||
drop.subscribe(handler) | ||
|
||
with pytest.raises(RuntimeError) as e: | ||
drop.execute() | ||
|
||
assert "Handler throw" in str(e.value) | ||
assert "Drop throw" not in str(e.value) |