Update ollama config_flow task to use eager_start (#115455)

The test now adds a delay because it finished too fast
This commit is contained in:
J. Nick Koston 2024-04-13 10:54:21 -10:00 committed by GitHub
parent f452c5b84e
commit 0bd4064212
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -151,7 +151,6 @@ class OllamaConfigFlow(ConfigFlow, domain=DOMAIN):
self.download_task = self.hass.async_create_background_task( self.download_task = self.hass.async_create_background_task(
self.client.pull(self.model), self.client.pull(self.model),
f"Downloading {self.model}", f"Downloading {self.model}",
eager_start=False,
) )
if self.download_task.done(): if self.download_task.done():

View File

@ -205,6 +205,10 @@ async def test_download_error(hass: HomeAssistant) -> None:
ollama.DOMAIN, context={"source": config_entries.SOURCE_USER} ollama.DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
async def _delayed_runtime_error(*args, **kwargs):
await asyncio.sleep(0)
raise RuntimeError
with ( with (
patch( patch(
"homeassistant.components.ollama.config_flow.ollama.AsyncClient.list", "homeassistant.components.ollama.config_flow.ollama.AsyncClient.list",
@ -212,7 +216,7 @@ async def test_download_error(hass: HomeAssistant) -> None:
), ),
patch( patch(
"homeassistant.components.ollama.config_flow.ollama.AsyncClient.pull", "homeassistant.components.ollama.config_flow.ollama.AsyncClient.pull",
side_effect=RuntimeError(), _delayed_runtime_error,
), ),
): ):
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(