| 1 |
import sys |
| 2 |
import time |
| 3 |
from typing import Any |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from ..util import busy_wait, flaky_in_ci |
| 8 |
from .util import parametrize_setstatprofile |
| 9 |
|
| 10 |
|
| 11 |
class CallCounter: |
| 12 |
def __init__(self) -> None: |
| 13 |
self.count = 0 |
| 14 |
|
| 15 |
def __call__(self, *args: Any, **kwds: Any) -> Any: |
| 16 |
self.count += 1 |
| 17 |
|
| 18 |
|
| 19 |
@flaky_in_ci |
| 20 |
@parametrize_setstatprofile |
| 21 |
def test_100ms(setstatprofile): |
| 22 |
counter = CallCounter() |
| 23 |
setstatprofile(counter, 0.1) |
| 24 |
busy_wait(1.0) |
| 25 |
setstatprofile(None) |
| 26 |
assert 8 < counter.count < 12 |
| 27 |
|
| 28 |
|
| 29 |
@flaky_in_ci |
| 30 |
@parametrize_setstatprofile |
| 31 |
def test_10ms(setstatprofile): |
| 32 |
counter = CallCounter() |
| 33 |
setstatprofile(counter, 0.01) |
| 34 |
busy_wait(1.0) |
| 35 |
setstatprofile(None) |
| 36 |
assert 70 <= counter.count <= 130 |
| 37 |
|
| 38 |
|
| 39 |
@parametrize_setstatprofile |
| 40 |
def test_internal_object_compatibility(setstatprofile): |
| 41 |
setstatprofile(CallCounter(), 1e6) |
| 42 |
|
| 43 |
profile_state = sys.getprofile() |
| 44 |
|
| 45 |
print(repr(profile_state)) |
| 46 |
print(str(profile_state)) |
| 47 |
print(profile_state) |
| 48 |
print(type(profile_state)) |
| 49 |
print(type(profile_state).__name__) |
| 50 |
|
| 51 |
setstatprofile(None) |