Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_hgutil.py
# Copyright (C) 2020-2021 The Software Heritage developers | # Copyright (C) 2020-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import signal | |||||
import time | import time | ||||
import traceback | import traceback | ||||
from mercurial import hg # type: ignore | from mercurial import hg # type: ignore | ||||
import pytest | import pytest | ||||
from .. import hgutil | from .. import hgutil | ||||
def test_clone_timeout(monkeypatch): | def test_clone_timeout(monkeypatch): | ||||
src = "https://www.mercurial-scm.org/repo/hello" | src = "https://www.mercurial-scm.org/repo/hello" | ||||
dest = "/dev/null" | dest = "/dev/null" | ||||
timeout = 1 | timeout = 0.1 | ||||
def clone(*args, **kwargs): | def clone(*args, **kwargs): | ||||
time.sleep(5) | # ignore SIGTERM to force sigkill | ||||
signal.signal(signal.SIGTERM, lambda signum, frame: None) | |||||
time.sleep(2) | |||||
monkeypatch.setattr(hg, "clone", clone) | monkeypatch.setattr(hg, "clone", clone) | ||||
with pytest.raises(hgutil.CloneTimeout) as e: | with pytest.raises(hgutil.CloneTimeout) as e: | ||||
hgutil.clone(src, dest, timeout) | hgutil.clone(src, dest, timeout) | ||||
assert e.value.args == (src, timeout) | killed = True | ||||
assert e.value.args == (src, timeout, killed) | |||||
def test_clone_error(caplog, tmp_path, monkeypatch): | def test_clone_error(caplog, tmp_path, monkeypatch): | ||||
src = "https://www.mercurial-scm.org/repo/hello" | src = "https://www.mercurial-scm.org/repo/hello" | ||||
dest = "/dev/null" | dest = "/dev/null" | ||||
expected_traceback = "Some traceback" | expected_traceback = "Some traceback" | ||||
def clone(*args, **kwargs): | def clone(*args, **kwargs): | ||||
Show All 11 Lines |