diff --git a/src/tribler/core/components/component.py b/src/tribler/core/components/component.py index c17ebd0c519..f66830a182f 100644 --- a/src/tribler/core/components/component.py +++ b/src/tribler/core/components/component.py @@ -56,6 +56,7 @@ async def start(self): # Tribler GUI will restart the process and the database will be recreated. process_manager = get_global_process_manager() process_manager.sys_exit(EXITCODE_DATABASE_IS_CORRUPTED, e) + return # Added for clarity; actually, the code raised SystemExit on the previous line if self.session.failfast: raise e diff --git a/src/tribler/core/components/tests/test_base_component.py b/src/tribler/core/components/tests/test_base_component.py index 49cfd7a0740..e7ea4fc56f0 100644 --- a/src/tribler/core/components/tests/test_base_component.py +++ b/src/tribler/core/components/tests/test_base_component.py @@ -1,9 +1,12 @@ +from unittest.mock import patch + import pytest from tribler.core.components.component import Component from tribler.core.components.exceptions import MissedDependency, MultipleComponentsFound, NoneComponent from tribler.core.components.session import Session from tribler.core.config.tribler_config import TriblerConfig +from tribler.core.utilities.db_corruption_handling.base import DatabaseIsCorrupted class ComponentTestException(Exception): @@ -46,6 +49,20 @@ class TestComponentB(TestComponent): assert component.stopped +@patch('tribler.core.components.component.get_global_process_manager') +async def test_session_start_database_corruption_detected(get_global_process_manager, tribler_config): + exception = DatabaseIsCorrupted('db_path_string') + + class TestComponent(Component): + async def run(self): + raise exception + + component = TestComponent() + + await component.start() + get_global_process_manager().sys_exit.assert_called_once_with(99, exception) + + class ComponentA(Component): pass