Files
dvc/tests/unit/remote/test_slow_link_detection.py
T
Ruslan Kuprieiev 88660f6a66 dvc: use transfer in checkout/doctor/odb
All three of those use more or less the same logic for testing different
link types and maybe then using them. So now instead of having 3
implementations, we'll have just one.

Filesystem `transfer` now will not try to catch particular errno's, but
instead will just ignore any OSError and move down to the next link type
to try out, and if the last one fails - it will raise the last exception,
so if it is a common problem - we'll be able to see it.

This patch also removes `odb.confirmed_cache_type`, as it was caching
link type that is not really a cache-level thing, but rather a checkout thing,
that should only be cached for particular objects we are linking, as multiple
objects could be linked to different filesystems from the same odb (e.g.
external local output on hdd and local data on your ssd).

Next step here will be to introduce metadata diff, so that we can get rid of
temporary Link wrapper and introduce Transfer and corresponding transfer
config, that will know what links to use and could have some other things
like callbacks, so we don't continue passing dozens of kwargs along the stack.

Continuing from #6963

Fixes #6980
2021-11-15 22:50:00 +02:00

48 lines
1.3 KiB
Python

import pytest
import dvc.objects.db.slow_link_detection
from dvc.objects.db.slow_link_detection import slow_link_guard
@pytest.fixture(autouse=True)
def timeout_immediately(monkeypatch):
monkeypatch.setattr(
dvc.objects.db.slow_link_detection, "timeout_seconds", 0.0
)
@pytest.fixture
def make_remote(mocker):
def _make_remote(cache_type=None, should_warn=True):
remote = mocker.Mock()
remote.cache_types = cache_type
remote.slow_link_warning = should_warn
return remote
return _make_remote
def test_show_warning_once(caplog, make_remote):
remote = make_remote()
slow_link_guard(lambda x, y: None)(None, remote)
slow_link_guard(lambda x, y: None)(None, remote)
slow_link_detection = dvc.objects.db.slow_link_detection
message = slow_link_detection.message # noqa, pylint: disable=no-member
assert len(caplog.records) == 1
assert caplog.records[0].message == message
def test_dont_warn_when_cache_type_is_set(caplog, make_remote):
remote = make_remote(cache_type="copy")
slow_link_guard(lambda x, y: None)(None, remote)
assert len(caplog.records) == 0
def test_dont_warn_when_warning_is_disabled(caplog, make_remote):
remote = make_remote(should_warn=False)
slow_link_guard(lambda x, y: None)(None, remote)
assert len(caplog.records) == 0