Detect blocking ssl context creation in the event loop (#123240)
This commit is contained in:
parent
fe4e6f24f5
commit
1eaaa00687
2 changed files with 43 additions and 0 deletions
|
@ -5,6 +5,7 @@ import glob
|
|||
import importlib
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
import ssl
|
||||
import time
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
@ -330,6 +331,29 @@ async def test_protect_loop_walk(
|
|||
assert "Detected blocking call to walk with args" not in caplog.text
|
||||
|
||||
|
||||
async def test_protect_loop_load_default_certs(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test SSLContext.load_default_certs calls in the loop are logged."""
|
||||
with patch.object(block_async_io, "_IN_TESTS", False):
|
||||
block_async_io.enable()
|
||||
context = ssl.create_default_context()
|
||||
assert "Detected blocking call to load_default_certs" in caplog.text
|
||||
assert context
|
||||
|
||||
|
||||
async def test_protect_loop_load_verify_locations(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test SSLContext.load_verify_locations calls in the loop are logged."""
|
||||
with patch.object(block_async_io, "_IN_TESTS", False):
|
||||
block_async_io.enable()
|
||||
context = ssl.create_default_context()
|
||||
with pytest.raises(OSError):
|
||||
context.load_verify_locations("/dev/null")
|
||||
assert "Detected blocking call to load_verify_locations" in caplog.text
|
||||
|
||||
|
||||
async def test_open_calls_ignored_in_tests(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test opening a file in tests is ignored."""
|
||||
assert block_async_io._IN_TESTS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue