Reload services on debounced file edits and replacement saves
This commit is contained in:
parent
15e4ed81a2
commit
dc24c4d4fe
1 changed files with 77 additions and 9 deletions
27
tests/test_cli_regressions.py
Normal file
27
tests/test_cli_regressions.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from threading import Event
|
||||
|
||||
from watchdog.events import FileClosedEvent, FileModifiedEvent, FileMovedEvent
|
||||
|
||||
from great_ai.deploy.reload_event_handler import ReloadEventHandler
|
||||
|
||||
|
||||
def test_reload_debounces_edit_and_replacement_events() -> None:
|
||||
completed = Event()
|
||||
calls = []
|
||||
|
||||
def restart() -> None:
|
||||
calls.append("restart")
|
||||
completed.set()
|
||||
|
||||
handler = ReloadEventHandler(restart, debounce_seconds=0.02)
|
||||
try:
|
||||
handler.dispatch(FileModifiedEvent("service.py"))
|
||||
handler.dispatch(FileClosedEvent("service.py"))
|
||||
handler.dispatch(FileMovedEvent("temporary", "service.py"))
|
||||
assert completed.wait(timeout=2)
|
||||
assert calls == ["restart"]
|
||||
handler.dispatch(FileModifiedEvent("__service__.py"))
|
||||
finally:
|
||||
handler.close()
|
||||
handler.dispatch(FileModifiedEvent("service.py"))
|
||||
assert calls == ["restart"]
|
||||
Loading…
Reference in a new issue