Skip to content

Commit 51614e2

Browse files
committed
use new test handshake for task.wait_until() instead of looping
1 parent e5d0111 commit 51614e2

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

tests/test_function.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ast import literal_eval
44
import asyncio
55
from datetime import datetime as dt
6-
import time
76

87
from custom_components.pyscript.const import CONF_ALLOW_ALL_IMPORTS, CONF_HASS_IS_GLOBAL, DOMAIN
98
from custom_components.pyscript.function import Function
@@ -259,7 +258,7 @@ def func4(trigger_type=None, event_type=None, **kwargs):
259258
global seq_num
260259
261260
seq_num += 1
262-
res = task.wait_until(event_trigger=["test_event4b", "arg1 == 25 and arg2 == 35"], timeout=10)
261+
res = task.wait_until(event_trigger=["test_event4b", "arg1 == 25 and arg2 == 35"], timeout=10, __test_handshake__=["pyscript.done2", seq_num])
263262
log.info(f"func4 trigger_type = {res}, event_type = {event_type}, event_data = {kwargs}")
264263
kwargs["context"] = {"user_id": kwargs["context"].user_id, "parent_id": kwargs["context"].parent_id, "id": "1234"}
265264
res["context"] = kwargs["context"]
@@ -599,12 +598,10 @@ def func9(var_name=None, value=None, old_value=None):
599598
seq_num += 1
600599
hass.states.async_set("pyscript.f4var2", 2)
601600
hass.bus.async_fire("test_event4", {"arg1": 20, "arg2": 30})
602-
t_now = time.monotonic()
603-
while notify_q.empty() and time.monotonic() < t_now + 4:
604-
hass.bus.async_fire("test_event4b", {"arg1": 15, "arg2": 25})
605-
hass.bus.async_fire("test_event4b", {"arg1": 20, "arg2": 25})
606-
hass.bus.async_fire("test_event4b", {"arg1": 25, "arg2": 35})
607-
await asyncio.sleep(2e-3)
601+
assert literal_eval(await wait_until_done(notify_q2)) == seq_num
602+
hass.bus.async_fire("test_event4b", {"arg1": 20, "arg2": 25})
603+
hass.bus.async_fire("test_event4b", {"arg1": 15, "arg2": 25})
604+
hass.bus.async_fire("test_event4b", {"arg1": 25, "arg2": 35})
608605
trig = {
609606
"trigger_type": "event",
610607
"event_type": "test_event4b",

tests/test_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ async def test_jupyter_kernel_no_connection_timeout(hass, caplog):
513513
#
514514
# There is a race condition waiting for the log message, so we need to poll
515515
#
516-
for _ in range(50):
516+
for _ in range(1000):
517517
if "No connections to session jupyter_" in caplog.text:
518518
break
519519
await asyncio.sleep(2e-3)

0 commit comments

Comments
 (0)