Skip to content

Commit

Permalink
Fix flakey influxdb test (home-assistant#115442)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Apr 11, 2024
1 parent cfda8f6 commit e368004
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/components/influxdb/test_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests for the InfluxDB component."""

import asyncio
from dataclasses import dataclass
import datetime
from http import HTTPStatus
Expand Down Expand Up @@ -1572,12 +1573,21 @@ async def test_invalid_inputs_error(
await _setup(hass, mock_client, config_ext, get_write_api)

write_api = get_write_api(mock_client)
write_api.side_effect = test_exception

write_api_done_event = asyncio.Event()

def wait_for_write(*args, **kwargs):
hass.loop.call_soon_threadsafe(write_api_done_event.set)
raise test_exception

write_api.side_effect = wait_for_write

with patch(f"{INFLUX_PATH}.time.sleep") as sleep:
write_api_done_event.clear()
hass.states.async_set("fake.something", 1)
await hass.async_block_till_done()
await async_wait_for_queue_to_process(hass)
await write_api_done_event.wait()
await hass.async_block_till_done()

write_api.assert_called_once()
Expand Down

0 comments on commit e368004

Please sign in to comment.