Skip to content

Commit a25063d

Browse files
committed
added some more tests for blocking and limit service call kw args
1 parent 713f949 commit a25063d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_function.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,54 @@ async def test_service_call_params(hass):
846846

847847
# Stop all tasks to avoid conflicts with other tests
848848
await Function.reaper_stop()
849+
850+
851+
async def test_serive_call_blocking(hass, caplog):
852+
"""Test that service calls with blocking=True actually block."""
853+
notify_q = asyncio.Queue(0)
854+
855+
await setup_script(
856+
hass,
857+
notify_q,
858+
[dt(2020, 7, 1, 12, 0, 0, 0)],
859+
"""
860+
seq_num = 0
861+
862+
@time_trigger("startup")
863+
def func_startup():
864+
global seq_num
865+
866+
seq_num += 1
867+
pyscript.var1 = 1
868+
pyscript.service1(blocking=True)
869+
pyscript.done = [seq_num, pyscript.var1]
870+
871+
seq_num += 1
872+
pyscript.service1(blocking=True)
873+
pyscript.done = [seq_num, pyscript.var1]
874+
875+
seq_num += 1
876+
service.call("pyscript", "service1", blocking=True)
877+
pyscript.done = [seq_num, pyscript.var1]
878+
879+
seq_num += 1
880+
pyscript.var1 = int(pyscript.var1) + 1
881+
service.call("pyscript", "long_sleep", blocking=True, limit=1e-6)
882+
pyscript.done = [seq_num, pyscript.var1]
883+
884+
@service
885+
def long_sleep():
886+
task.delay(10000)
887+
888+
@service
889+
def service1():
890+
pyscript.var1 = int(pyscript.var1) + 1
891+
892+
""",
893+
config={DOMAIN: {CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True}},
894+
)
895+
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
896+
assert literal_eval(await wait_until_done(notify_q)) == [1, "2"]
897+
assert literal_eval(await wait_until_done(notify_q)) == [2, "3"]
898+
assert literal_eval(await wait_until_done(notify_q)) == [3, "4"]
899+
assert literal_eval(await wait_until_done(notify_q)) == [4, "5"]

0 commit comments

Comments
 (0)