Skip to content

Commit 6403675

Browse files
authored
[core] Fix flaky recursive cancel test (#58923)
This test was flaky before, making it more deterministic now by cancelling only once the outer and inner task are both running and making sure they're running before launching the many_resources task. The flaky failure was the ray.get on many_resources returning before the cancel. https://buildkite.com/ray-project/postmerge/builds/14463#019a99a6-acf2-4e28-89d3-2abc99eb93ac/609-913 --------- Signed-off-by: dayshah <dhyey2019@gmail.com>
1 parent ffa560a commit 6403675

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

python/ray/tests/test_cancel.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,29 +458,32 @@ def remote_wait(sg):
458458

459459
@pytest.mark.parametrize("use_force", [True, False])
460460
def test_recursive_cancel(shutdown_only, use_force):
461-
ray.init(num_cpus=4)
461+
ray.init(num_cpus=2)
462462

463463
@ray.remote(num_cpus=1)
464-
def inner():
464+
def inner(signal_actor):
465+
signal_actor.send.remote()
465466
while True:
466467
time.sleep(0.1)
467468

468469
@ray.remote(num_cpus=1)
469-
def outer():
470-
x = [inner.remote()]
471-
print(x)
470+
def outer(signal_actor):
471+
_ = inner.remote(signal_actor)
472472
while True:
473473
time.sleep(0.1)
474474

475-
@ray.remote(num_cpus=4)
475+
@ray.remote(num_cpus=2)
476476
def many_resources():
477-
return 300
477+
return True
478478

479-
outer_fut = outer.remote()
479+
signal_actor = SignalActor.remote()
480+
outer_fut = outer.remote(signal_actor)
481+
# Wait until both inner and outer are running
482+
ray.get(signal_actor.wait.remote())
480483
many_fut = many_resources.remote()
481484
with pytest.raises(GetTimeoutError):
482485
ray.get(many_fut, timeout=1)
483-
ray.cancel(outer_fut)
486+
ray.cancel(outer_fut, force=use_force)
484487
with pytest.raises(valid_exceptions(use_force)):
485488
ray.get(outer_fut, timeout=10)
486489

0 commit comments

Comments
 (0)