mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 21:25:13 +02:00
no reason to ever enable twice
This commit is contained in:
@@ -160,7 +160,7 @@ _BLOCKED_CALLS = BlockedCalls(set())
|
||||
def enable() -> None:
|
||||
"""Enable the detection of blocking calls in the event loop."""
|
||||
if _BLOCKED_CALLS.calls:
|
||||
return
|
||||
raise RuntimeError("Blocking call detection is already enabled")
|
||||
|
||||
loop_thread_id = threading.get_ident()
|
||||
for blocking_call in BLOCKING_CALLS:
|
||||
|
@@ -229,6 +229,17 @@ async def test_protect_open(caplog: pytest.LogCaptureFixture) -> None:
|
||||
assert "Detected blocking call to open with args" in caplog.text
|
||||
|
||||
|
||||
async def test_enable_multiple_times(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test trying to enable multiple times."""
|
||||
with patch.object(block_async_io, "_IN_TESTS", False):
|
||||
block_async_io.enable()
|
||||
|
||||
with pytest.raises(
|
||||
RuntimeError, match="Blocking call detection is already enabled"
|
||||
):
|
||||
block_async_io.enable()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path",
|
||||
[
|
||||
|
Reference in New Issue
Block a user