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
Log a connector exit #348
Log a connector exit #348
Conversation
Codecov Report
@@ Coverage Diff @@
## master #348 +/- ##
==========================================
- Coverage 100% 99.43% -0.57%
==========================================
Files 17 17
Lines 877 886 +9
==========================================
+ Hits 877 881 +4
- Misses 0 5 +5
Continue to review full report at Codecov.
|
0d34746
to
70b1925
Compare
70b1925
to
1544424
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that You could test this by creating a side_effect and set it to future.exception() (like I’ve done when testing for the aiohttp.ClientOsError() on the parsers), then mock the logging call and see if the logging function was called.
I’m on the phone now so I can’t really give you links, but I’ll edit this post once I’m at home 👍
--EDIT--
As promised here's the code to give you an idea how to test for those things:
Mocking ClientOSError()
[...]
with amock.patch.object(luisai, 'call_luisai') as mocked_call:
mocked_call.side_effect = ClientOSError()
# Call the parser, this will make the side_effect run and return a ClientOSError()
await luisai.parse_luisai(opsdroid, message, opsdroid.config['parsers'][0])
# Assert if the call was successful, the test should show the ClientOSError message when it passes
self.assertTrue(mocked_call.called)
Logging call test
def test_welcome_message(self):
config = {"welcome-message": True}
with mock.patch('opsdroid.__main__._LOGGER.info') as logmock:
opsdroid.welcome_message(config)
self.assertTrue(logmock.called)
The logging call test is pretty much similar to the clientOSError one. Hope this helps you to create your tests, let me know if you need any further help 👍
👍 this is a great idea. Agree with @FabioRosado on testing methods. Also a couple of questions:
Also I wonder if it would be useful for connectors to have enter and exit methods and to be instantiated with an |
The issue is if the
The Python documentation on |
@Cadair happy with your comments. Could you please look at adding tests so I can get this merged. |
@Cadair I've updated my post, if you still need help creating tests let me know and I'll give you a hand 👍 |
@Cadair any update on this? |
Sorry, other things have stolen my attention. I will try to get back to it asap. |
It's been more than 30 days since the last activity on this PR. I'm going to close it but please feel free to reopen it if you wish to continue this work. |
Description
If a connector exits, especially if it exits with an error we should log this. This adds a done callback on the listener task which logs the exception is one is raised. If the task was cancelled we do not log it as if the task is cancelled opsdroid is shutting down.
I am not sure how to write a unit test for this?
Status
READY
Type of change
How Has This Been Tested?
Make a connector raise an exception which is not caught, i.e. to exit the coroutine with an exception.
Make a connector where the listen coroutine returns a value.
Checklist: