Skip to content

Commit c68d8df

Browse files
authored
deflake flaky module watcher tests (#9367)
1 parent 2b0f5e1 commit c68d8df

1 file changed

Lines changed: 69 additions & 7 deletions

File tree

tests/_runtime/reload/test_module_watcher.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,16 @@ def foo():
151151
)
152152

153153
# wait for the watcher to pick up the change
154-
await asyncio.sleep(INTERVAL * 3)
154+
retries = 0
155+
while retries < 10:
156+
await asyncio.sleep(INTERVAL)
157+
retries += 1
158+
if (
159+
k.graph.cells[er_1.cell_id].stale
160+
and k.graph.cells[er_2.cell_id].stale
161+
):
162+
break
163+
155164
assert k.graph.cells[er_1.cell_id].stale
156165
assert k.graph.cells[er_2.cell_id].stale
157166
assert not k.graph.cells[er_3.cell_id].stale
@@ -162,6 +171,7 @@ def foo():
162171
assert k.globals["x"] == 2
163172

164173

174+
@pytest.mark.flaky(reruns=3)
165175
async def test_reload_nested_module_function(
166176
tmp_path: pathlib.Path,
167177
py_modname: str,
@@ -206,7 +216,16 @@ def foo():
206216
update_file(nested_module, "func = lambda : 2")
207217

208218
# wait for the watcher to pick up the change
209-
await asyncio.sleep(INTERVAL * 3)
219+
retries = 0
220+
while retries < 10:
221+
await asyncio.sleep(INTERVAL)
222+
retries += 1
223+
if (
224+
k.graph.cells[er_1.cell_id].stale
225+
and k.graph.cells[er_2.cell_id].stale
226+
):
227+
break
228+
210229
assert k.graph.cells[er_1.cell_id].stale
211230
assert k.graph.cells[er_2.cell_id].stale
212231
assert not k.graph.cells[er_3.cell_id].stale
@@ -217,6 +236,7 @@ def foo():
217236
assert k.globals["x"] == 2
218237

219238

239+
@pytest.mark.flaky(reruns=3)
220240
async def test_reload_nested_module_import_module(
221241
tmp_path: pathlib.Path,
222242
py_modname: str,
@@ -261,7 +281,16 @@ def foo():
261281
update_file(nested_module, "func = lambda : 2")
262282

263283
# wait for the watcher to pick up the change
264-
await asyncio.sleep(INTERVAL * 3)
284+
retries = 0
285+
while retries < 10:
286+
await asyncio.sleep(INTERVAL)
287+
retries += 1
288+
if (
289+
k.graph.cells[er_1.cell_id].stale
290+
and k.graph.cells[er_2.cell_id].stale
291+
):
292+
break
293+
265294
assert k.graph.cells[er_1.cell_id].stale
266295
assert k.graph.cells[er_2.cell_id].stale
267296
assert not k.graph.cells[er_3.cell_id].stale
@@ -335,6 +364,7 @@ def foo():
335364
assert k.globals["x"] == 2
336365

337366

367+
@pytest.mark.flaky(reruns=3)
338368
async def test_reload_package(
339369
tmp_path: pathlib.Path,
340370
execution_kernel: Kernel,
@@ -368,7 +398,16 @@ async def test_reload_package(
368398
update_file(nested_module, "func = lambda : 2")
369399

370400
# wait for the watcher to pick up the change
371-
await asyncio.sleep(INTERVAL * 3)
401+
retries = 0
402+
while retries < 10:
403+
await asyncio.sleep(INTERVAL)
404+
retries += 1
405+
if (
406+
k.graph.cells[er_1.cell_id].stale
407+
and k.graph.cells[er_2.cell_id].stale
408+
):
409+
break
410+
372411
assert k.graph.cells[er_1.cell_id].stale
373412
assert k.graph.cells[er_2.cell_id].stale
374413
assert not k.graph.cells[er_3.cell_id].stale
@@ -441,6 +480,7 @@ def foo():
441480
assert k.globals["x"] == 2
442481

443482

483+
@pytest.mark.flaky(reruns=3)
444484
async def test_reload_with_modified_cell(
445485
tmp_path: pathlib.Path,
446486
py_modname: str,
@@ -479,7 +519,16 @@ def foo():
479519
)
480520

481521
# wait for the watcher to pick up the change
482-
await asyncio.sleep(INTERVAL * 3)
522+
retries = 0
523+
while retries < 10:
524+
await asyncio.sleep(INTERVAL)
525+
retries += 1
526+
if (
527+
k.graph.cells[er_1.cell_id].stale
528+
and k.graph.cells[er_2.cell_id].stale
529+
):
530+
break
531+
483532
assert k.graph.cells[er_1.cell_id].stale
484533
assert k.graph.cells[er_2.cell_id].stale
485534
assert not k.graph.cells[er_3.cell_id].stale
@@ -924,6 +973,7 @@ async def test_module_watcher_processes_flag(
924973
class TestModuleWatcherEdgeCases:
925974
"""Tests for edge cases in module watching"""
926975

976+
@pytest.mark.flaky(reruns=3)
927977
async def test_module_watcher_handles_deleted_cell(
928978
self,
929979
tmp_path: pathlib.Path,
@@ -969,12 +1019,18 @@ def foo():
9691019
)
9701020

9711021
# Wait for watcher to pick up change
972-
await asyncio.sleep(INTERVAL * 3)
1022+
retries = 0
1023+
while retries < 10:
1024+
await asyncio.sleep(INTERVAL)
1025+
retries += 1
1026+
if k.graph.cells[er_1.cell_id].stale:
1027+
break
9731028

9741029
# Only er_1 should be stale (er_2 was deleted)
9751030
assert k.graph.cells[er_1.cell_id].stale
9761031
assert er_2.cell_id not in k.graph.cells
9771032

1033+
@pytest.mark.flaky(reruns=3)
9781034
async def test_module_watcher_cache_invalidation(
9791035
self,
9801036
tmp_path: pathlib.Path,
@@ -999,7 +1055,13 @@ async def test_module_watcher_cache_invalidation(
9991055
update_file(py_file, "def foo(): return 2")
10001056

10011057
# Wait for watcher
1002-
await asyncio.sleep(INTERVAL * 3)
1058+
retries = 0
1059+
while retries < 10:
1060+
await asyncio.sleep(INTERVAL)
1061+
retries += 1
1062+
if k.graph.cells[er_1.cell_id].stale:
1063+
break
1064+
10031065
assert k.graph.cells[er_1.cell_id].stale
10041066

10051067
# Run stale cells

0 commit comments

Comments
 (0)