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

[Main] test_unhandled_error_observer_only_message fails randomly #6542

Closed
drew2a opened this issue Nov 10, 2021 · 5 comments · Fixed by #6543
Closed

[Main] test_unhandled_error_observer_only_message fails randomly #6542

drew2a opened this issue Nov 10, 2021 · 5 comments · Fixed by #6543

Comments

@drew2a
Copy link
Contributor

drew2a commented Nov 10, 2021

I saw test_unhandled_error_observer_only_message fail on Windows during the #6540:

Console full

async def test_unhandled_error_observer_only_message():
        # test that unhandled exception, represented by message, reported to the GUI
        context = {'message': 'Any'}
        CoreExceptionHandler.report_callback = MagicMock()
        CoreExceptionHandler.unhandled_error_observer(None, context)
        CoreExceptionHandler.report_callback.assert_called()
    
        # get the argument that has been passed to the report_callback
        reported_error = CoreExceptionHandler.report_callback.call_args_list[-1][0][0]
        assert reported_error.type == 'Exception'
        assert reported_error.text == 'Received error without exception: Any'
        assert reported_error.long_text == 'Exception: Received error without exception: Any\n'
        assert not reported_error.event
        assert reported_error.context == '{}'
        assert reported_error.should_stop
>       assert reported_error.requires_user_consent
E       AssertionError: assert False
E        +  where False = ReportedError(type='Exception', text='Received error without exception: Any', event={}, long_text='Exception: Received error without exception: Any\n', context='{}', should_stop=True, requires_user_consent=False).requires_user_consent

src\tribler-core\tribler_core\components\reporter\tests\test_exception_handler.py:93: AssertionError

as well as test_unhandled_error_observer_exception:

@patch(f'{sentry_reporter.__name__}.{SentryReporter.__name__}.{SentryReporter.event_from_exception.__name__}',
           new=MagicMock(return_value={'sentry': 'event'}))
    async def test_unhandled_error_observer_exception():
        # test that unhandled exception, represented by Exception, reported to the GUI
        context = {'exception': raise_error(AttributeError('Any')), 'Any key': 'Any value'}
        CoreExceptionHandler.report_callback = MagicMock()
        CoreExceptionHandler.unhandled_error_observer(None, context)
        CoreExceptionHandler.report_callback.assert_called()
    
        # get the argument that has been passed to the report_callback
        reported_error = CoreExceptionHandler.report_callback.call_args_list[-1][0][0]
        assert reported_error.type == 'AttributeError'
        assert reported_error.text == 'Any'
        assert 'raise_error' in reported_error.long_text
        assert reported_error.event == {'sentry': 'event'}
        assert reported_error.context == "{'Any key': 'Any value'}"
        assert reported_error.should_stop
>       assert reported_error.requires_user_consent
E       assert False
E        +  where False = ReportedError(type='AttributeError', text='Any', event={'sentry': 'event'}, long_text='Traceback (most recent call las...raise error\nAttributeError: Any\n', context="{'Any key': 'Any value'}", should_stop=True, requires_user_consent=False).requires_user_consent
@drew2a drew2a self-assigned this Nov 10, 2021
@drew2a drew2a added this to the 7.12.0 December milestone Nov 10, 2021
@drew2a
Copy link
Contributor Author

drew2a commented Nov 10, 2021

My guess is the root cause of the error is the following: CoreExceptionHandler (that designed as a singletone) is tested by async tests.

And the fragile part of the failed is:

async def test_unhandled_error_observer_only_message():
     ...
    # get the argument that has been passed to the report_callback
    reported_error = CoreExceptionHandler.report_callback.call_args_list[-1][0][0]
    ...    

@kozlovsky
Copy link
Contributor

As we mock global objects, we should not run tests in parallel in multiple threads. I think it should not significantly affect performance, as Python's use of GIL prevents simultaneous execution anyway.

@devos50
Copy link
Contributor

devos50 commented Dec 11, 2021

This test seemed to fail again when testing #6600 with the following traceback:

exception_handler = <tribler_core.components.reporter.exception_handler.CoreExceptionHandler object at 0x00000000299319D0>

    async def test_unhandled_error_observer_only_message(exception_handler):
        # test that unhandled exception, represented by message, reported to the GUI
        context = {'message': 'Any'}
        exception_handler.report_callback = MagicMock()
        exception_handler.unhandled_error_observer(None, context)
        exception_handler.report_callback.assert_called()
    
        # get the argument that has been passed to the report_callback
        reported_error = exception_handler.report_callback.call_args_list[-1][0][0]
        assert reported_error.type == 'Exception'
        assert reported_error.text == 'Received error without exception: Any'
        assert reported_error.long_text == 'Exception: Received error without exception: Any\n'
>       assert not reported_error.event
E       AssertionError: assert not {'a': 'b'}
E        +  where {'a': 'b'} = ReportedError(type='Exception', text='Received error without exception: Any', event={'a': 'b'}, long_text='Exception: Received error without exception: Any\n', context='{}', should_stop=True).event

src\tribler-core\tribler_core\components\reporter\tests\test_exception_handler.py:94: AssertionError

Should we create a new issue or use this one?

@drew2a
Copy link
Contributor Author

drew2a commented Dec 13, 2021

Let's use this one.

@drew2a drew2a reopened this Dec 13, 2021
@drew2a drew2a removed their assignment Dec 13, 2021
@drew2a
Copy link
Contributor Author

drew2a commented Apr 11, 2022

All tested-related issues should be solved in #6851 after merging #6850 and #6855.

If the issue is encountered again, feel free to reopen it.

@drew2a drew2a closed this as completed Apr 11, 2022
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.

3 participants