Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky test: test_patched_db_session_default_duration_threshold #7675

Closed
drew2a opened this issue Nov 7, 2023 · 5 comments · Fixed by #7952
Closed

Flaky test: test_patched_db_session_default_duration_threshold #7675

drew2a opened this issue Nov 7, 2023 · 5 comments · Fixed by #7952

Comments

@drew2a
Copy link
Contributor

drew2a commented Nov 7, 2023

https://github.com/Tribler/tribler/actions/runs/6784825905/job/18441888974?pr=7667#step:6:2748 in #7667

================================== FAILURES ===================================
_____________ test_patched_db_session_default_duration_threshold ______________

tmp_path = WindowsPath('C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/test_patched_db_session_defaul0')

    def test_patched_db_session_default_duration_threshold(tmp_path):
        # The test checks that db_session uses the current dynamic value of SLOW_DB_SESSION_DURATION_THRESHOLD
        # if no duration_threshold was explicitly specified for db_session
    
        with patch('pony.orm.dbproviders.sqlite.provider_cls', pony_utils.PatchedSQLiteProvider):
            db = pony_utils.TrackedDatabase()
            db.bind('sqlite', str(tmp_path / 'db.sqlite'), create_db=True)
    
            class Entity1(db.Entity):
                a = Required(int)
    
            db.generate_mapping(create_tables=True)
    
            # We change the value of SLOW_DB_SESSION_DURATION_THRESHOLD, and the current value should be used by db_session
            with patch('tribler.core.utilities.pony_utils.SLOW_DB_SESSION_DURATION_THRESHOLD', 0.0):
                with patch.object(pony_utils.TriblerDbSession, '_format_warning',
                                  return_value='<warning text>') as format_warning_mock:
                    perform_queries(db, Entity1)
    
>           format_warning_mock.assert_called()

Entity1    = <class 'tribler.core.utilities.tests.test_pony_utils.test_patched_db_session_default_duration_threshold.<locals>.Entity1'>
db         = <tribler.core.utilities.pony_utils.TrackedDatabase object at 0x000001681A33EF40>
format_warning_mock = <MagicMock name='_format_warning' id='1546627798976'>
tmp_path   = WindowsPath('C:/Users/runneradmin/AppData/Local/Temp/pytest-of-runneradmin/pytest-0/test_patched_db_session_defaul0')

src\tribler\core\utilities\tests\test_pony_utils.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <MagicMock name='_format_warning' id='1546627798976'>

    def assert_called(self):
        """assert that the mock was called at least once
        """
        if self.call_count == 0:
            msg = ("Expected '%s' to have been called." %
                   (self._mock_name or 'mock'))
>           raise AssertionError(msg)
E           AssertionError: Expected '_format_warning' to have been called.

msg        = "Expected '_format_warning' to have been called."
self       = <MagicMock name='_format_warning' id='1546627798976'>

C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\unittest\mock.py:882: AssertionError

=========================== short test summary info ===========================
FAILED src/tribler/core/utilities/tests/test_pony_utils.py::test_patched_db_session_default_duration_threshold - AssertionError: Expected '_format_warning' to have been called.
===== 1 failed, 1322 passed, 3 skipped, 499 warnings in 346.12s (0:05:46) =====
@drew2a
Copy link
Contributor Author

drew2a commented Dec 6, 2023

@drew2a
Copy link
Contributor Author

drew2a commented Dec 8, 2023

@drew2a
Copy link
Contributor Author

drew2a commented Dec 18, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants