Skip to content

Commit 0159b43

Browse files
committed
Make test_execute more robust
1 parent 9a5b56b commit 0159b43

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ test = [
6565
"types-setuptools",
6666
"pytest",
6767
"pytest-timeout",
68+
"pytest-rerunfailures",
6869
"pytest-env",
6970
"httpx",
7071
"httpx-ws >=0.4.1",

tests/test_execute.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ async def recv(self) -> bytes:
8686

8787

8888
@pytest.mark.anyio
89+
@pytest.mark.flaky(reruns=2)
8990
@pytest.mark.parametrize("auth_mode", ("noauth",))
9091
async def test_execute(auth_mode, unused_tcp_port):
9192
url = f"http://127.0.0.1:{unused_tcp_port}"
@@ -152,7 +153,11 @@ def callback(aevent, events, event):
152153
):
153154
# connect to the shared notebook document
154155
# wait for file to be loaded and Y model to be created in server and client
155-
await anyio.sleep(0.5)
156+
with anyio.fail_after(1):
157+
while True:
158+
await anyio.sleep(0.1)
159+
if len(ynb.ycells) >= 2:
160+
break
156161
# execute notebook
157162
for cell_idx in range(2):
158163
response = await http.post(

tests/test_server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ def callback(aevent, events, event):
175175
):
176176
# connect to the shared notebook document
177177
# wait for file to be loaded and Y model to be created in server and client
178-
await anyio.sleep(0.5)
178+
with anyio.fail_after(1):
179+
while True:
180+
await anyio.sleep(0.1)
181+
if len(ynb.ycells) >= 2:
182+
break
179183
# execute notebook
180184
for cell_idx in range(2):
181185
response = requests.post(
@@ -215,10 +219,14 @@ async def connect_ywidget(url, guid):
215219
aconnect_ws(f"{url}/api/collaboration/room/ywidget:{guid}") as websocket,
216220
WebsocketProvider(ywidget_doc, Websocket(websocket, guid)),
217221
):
218-
await anyio.sleep(0.5)
219222
attrs = Map()
220223
model_name = Text()
221224
ywidget_doc["_attrs"] = attrs
222225
ywidget_doc["_model_name"] = model_name
226+
with anyio.fail_after(1):
227+
while True:
228+
await anyio.sleep(0.1)
229+
if len(attrs) > 0:
230+
break
223231
assert str(model_name) == "Switch"
224232
assert str(attrs) == '{"value":true}'

0 commit comments

Comments
 (0)