diff --git a/swh/loader/mercurial/hgutil.py b/swh/loader/mercurial/hgutil.py --- a/swh/loader/mercurial/hgutil.py +++ b/swh/loader/mercurial/hgutil.py @@ -154,16 +154,20 @@ if process.is_alive(): process.terminate() - # Give it a second (literally), then kill it + # Give it literally a second (in successive steps of 0.1 second), then kill it. # Can't use `process.join(1)` here, billiard appears to be bugged # https://github.com/celery/billiard/issues/270 killed = False - for _ in range(10): - time.sleep(0.1) + step = 0.1 + for _ in range(11): + print(f"sleep {step} second") + time.sleep(step) if not process.is_alive(): + print("process not alive, break") break else: killed = True + print(f"process {process.pid} to stop: killed=={killed}") os.kill(process.pid, signal.SIGKILL) raise CloneTimeout(src, timeout, killed) diff --git a/swh/loader/mercurial/tests/test_hgutil.py b/swh/loader/mercurial/tests/test_hgutil.py --- a/swh/loader/mercurial/tests/test_hgutil.py +++ b/swh/loader/mercurial/tests/test_hgutil.py @@ -9,18 +9,24 @@ from mercurial import hg # type: ignore import pytest +from swh.scheduler.utils import utcnow + from .. import hgutil def test_clone_timeout(monkeypatch): src = "https://www.mercurial-scm.org/repo/hello" dest = "/dev/null" - timeout = 0.1 + timeout = 1 + sleepy_time = 10 * timeout + assert sleepy_time > timeout - def clone(*args, **kwargs): + def clone(*args, sleepy_time=sleepy_time, **kwargs): # ignore SIGTERM to force sigkill signal.signal(signal.SIGTERM, lambda signum, frame: None) - time.sleep(2) + print(f"(false clone) {utcnow()} Sleep for {sleepy_time} seconds.") + time.sleep(sleepy_time) # we make sure we exceed the timeout + print(f"(false clone) {utcnow()} Slept but this should never get printed!") monkeypatch.setattr(hg, "clone", clone)