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

Support decoration of async functions #767

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pliner
Copy link
Contributor

@Pliner Pliner commented Feb 8, 2022

Fix #535

@Pliner Pliner force-pushed the fix-#535 branch 2 times, most recently from 81f873a to 5d79d22 Compare February 8, 2022 14:46
Signed-off-by: Yury Pliner <yury.pliner@gmail.com>
from concurrent.futures import ThreadPoolExecutor
import time
import unittest

import pytest
import aiounittest # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typestub is available


self.assertEqual(([], None, None, None), getargspec(f))

f()
self.assertNotEqual(0, self.registry.get_sample_value('g'))
self.assertTrue(0.05 <= self.registry.get_sample_value('g') <= 0.1)
Copy link
Contributor Author

@Pliner Pliner Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to check the expected duration. It makes more sense in a case of async functions to be sure that the decorator works fine.


self.assertEqual(([], None, None, None), getargspec(f))

f()
self.assertEqual(1, self.registry.get_sample_value('s_count'))
self.assertTrue(.05 < self.registry.get_sample_value('s_sum') < 0.1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


self.assertEqual(([], None, None, None), getargspec(f))

f()
self.assertEqual(1, self.registry.get_sample_value('h_count'))
self.assertEqual(1, self.registry.get_sample_value('h_bucket', {'le': '+Inf'}))
self.assertTrue(.05 < self.registry.get_sample_value('h_sum') < 0.1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -6,6 +6,7 @@ envlist = coverage-clean,py3.6,py3.7,py3.8,py3.9,py3.10,pypy3.7,py3.9-nooptional
deps =
coverage
pytest
aiounittest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unittest.IsolatedAsyncioTestCase is available for python 3.8+, so this module is needed to support async version of unittest.TestCase.

@Pliner
Copy link
Contributor Author

Pliner commented Feb 8, 2022

Only tests to check expected behaviour were added. I hope to finalise the PR after a merge of #766.

@camlee
Copy link

camlee commented Apr 24, 2022

Can I help move this forward in any way? I've implemented the code to handle async and pushed it here:
camlee@beae31a

It passes all of your unit tests.

@kakkoyun
Copy link
Member

Hey @Pliner, what's the latest state of this PR?

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

Successfully merging this pull request may close these issues.

Async context manager
3 participants