Changeset View
Standalone View
swh/fuse/tests/test_cache.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import os | |||||
from swh.fuse.tests.data.config import REGULAR_FILE | |||||
from swh.model.identifiers import parse_swhid | |||||
def test_cache_artifact(fuse_mntdir): | |||||
assert os.listdir(fuse_mntdir / "cache") == ["origin"] | |||||
(fuse_mntdir / "archive" / REGULAR_FILE).is_file() | |||||
swhid = parse_swhid(REGULAR_FILE) | |||||
assert os.listdir(fuse_mntdir / "cache") == [swhid.object_id[:2], "origin"] | |||||
def test_invalidate_artifact(fuse_mntdir): | |||||
zack: s/invalidate/purge/
(as "cache invalidation" means a different thing) | |||||
DEFAULT_CACHE_CONTENT = ["origin"] | |||||
assert os.listdir(fuse_mntdir / "cache") == DEFAULT_CACHE_CONTENT | |||||
# Access a content artifact... | |||||
(fuse_mntdir / "archive" / REGULAR_FILE).is_file() | |||||
assert os.listdir(fuse_mntdir / "cache") != DEFAULT_CACHE_CONTENT | |||||
# ... and remove it from cache | |||||
swhid = parse_swhid(REGULAR_FILE) | |||||
os.unlink(fuse_mntdir / "cache" / swhid.object_id[:2] / str(swhid)) | |||||
assert os.listdir(fuse_mntdir / "cache") == DEFAULT_CACHE_CONTENT | |||||
zackUnsubmitted Not Done Inline ActionsThis is a very surface-thing test, you're only testing that the directory entry is gone, not that the corresponding entry has actually been removed from the cache (which would be the actual underlying behavior). Unrelated question: is the FUSE cache emptied for sure before starting this test? (e.g., by test setup that creates a new instance) Because if it isn't you assertion here might fail if, for reasons unrelated to this test, there are other entries in the cache. zack: This is a very surface-thing test, you're only testing that the directory entry is gone, not… | |||||
haltodeAuthorUnsubmitted Done Inline ActionsI only have access to the path of the mounting dir in the unit tests, but since the cache/ listing is pretty much 1. read cache 2. create entries with sharded prefix, it should reflect directly the cache content. For unit tests the cache is set to be created in-memory in the fuse_mntdir fixture, so yes it is empty everytime a test start. haltode: I only have access to the path of the mounting dir in the unit tests, but since the cache/… |
s/invalidate/purge/
(as "cache invalidation" means a different thing)