Skip to content

Support decoration of async functions - #767

Draft
Pliner wants to merge 1 commit into
prometheus:masterfrom
Pliner:fix-#535
Draft

Support decoration of async functions #767
Pliner wants to merge 1 commit into
prometheus:masterfrom
Pliner:fix-#535

Conversation

@Pliner

Copy link
Copy Markdown
Contributor

Fix#535

@Pliner
Plinerforce-pushed the fix-#535 branch 2 times, most recently from 81f873a to 5d79d22CompareFebruary 8, 2022 14:46
Signed-off-by: Yury Pliner <yury.pliner@gmail.com>
Comment threadtests/test_core.py
import unittest

import pytest
import aiounittest # type: ignore

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

No typestub is available

Comment threadtests/test_core.py

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

@PlinerPlinerFeb 8, 2022

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threadtests/test_core.py

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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Comment threadtests/test_core.py
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Comment threadtox.ini
deps =
coverage
pytest
aiounittest

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

@camlee

camlee commented Apr 24, 2022

Copy link
Copy Markdown

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
Copy Markdown
Member

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

Sign up for freeto 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

@Pliner@camlee@kakkoyun