Skip to content

Commit

Permalink
Always return started as False once Zeroconf has been marked as done (
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored May 6, 2022
1 parent 59624a6 commit ed02e5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from unittest.mock import patch

import zeroconf as r
from zeroconf import _core, const, Zeroconf, current_time_millis
from zeroconf import _core, const, Zeroconf, current_time_millis, NotRunningException
from zeroconf.asyncio import AsyncZeroconf
from zeroconf._protocol import outgoing

Expand Down Expand Up @@ -798,3 +798,15 @@ def _background_register():

zc.close()
bgthread.join()


@pytest.mark.asyncio
@unittest.skipIf(sys.version_info[:3][1] < 8, 'Requires Python 3.8 or later to patch _async_setup')
@patch("zeroconf._core._STARTUP_TIMEOUT", 0)
@patch("zeroconf._core.AsyncEngine._async_setup")
async def test_event_loop_blocked(mock_start):
"""Test we raise NotRunningException when waiting for startup that times out."""
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
with pytest.raises(NotRunningException):
await aiozc.zeroconf.async_wait_for_start()
assert aiozc.zeroconf.started is False
2 changes: 1 addition & 1 deletion zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def __init__(
@property
def started(self) -> bool:
"""Check if the instance has started."""
return bool(self.engine.running_event and self.engine.running_event.is_set())
return bool(not self.done and self.engine.running_event and self.engine.running_event.is_set())

def start(self) -> None:
"""Start Zeroconf."""
Expand Down

0 comments on commit ed02e5d

Please sign in to comment.