Skip to content

Commit

Permalink
Add test for handling database corruption error during the component …
Browse files Browse the repository at this point in the history
…startup
  • Loading branch information
kozlovsky committed Nov 23, 2023
1 parent 87cdda9 commit 96e1ef8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tribler/core/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/tribler/core/components/tests/test_base_component.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):

Check warning on line 53 in src/tribler/core/components/tests/test_base_component.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/tribler/core/components/tests/test_base_component.py#L53

Unused argument '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

Expand Down

0 comments on commit 96e1ef8

Please sign in to comment.