diff options
Diffstat (limited to 'packages/meshbay-node/tests/test_index_cache.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_index_cache.py | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/packages/meshbay-node/tests/test_index_cache.py b/packages/meshbay-node/tests/test_index_cache.py index 8f0ff25..e4424d2 100644 --- a/packages/meshbay-node/tests/test_index_cache.py +++ b/packages/meshbay-node/tests/test_index_cache.py @@ -127,43 +127,33 @@ async def test_cache_survives_reopen(tmp_path): @pytest.mark.asyncio -async def test_put_v2_then_lookup_hits(cache): +@pytest.mark.parametrize("hv", [1, 2, 3]) +async def test_a_hit_keeps_the_version_it_was_hashed_under(cache, hv): + """An older scheme is served as is: the id is what TMDB matches, + thumbnails and playlists hang on.""" await cache.put("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash="partial_abc", type="video", added_at=42, - hash_version=2) + hash="old_id", type="video", added_at=42, + hash_version=hv) - hit = await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash_version=2) + hit = await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0) assert hit is not None - assert hit.hash == "partial_abc" - assert hit.hash_version == 2 + assert hit.hash == "old_id" + assert hit.hash_version == hv @pytest.mark.asyncio -async def test_lookup_misses_on_wrong_hash_version(cache): - await cache.put("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash="full_hash", type="video", added_at=42, - hash_version=1) - - assert await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash_version=2) is None - - -@pytest.mark.asyncio -async def test_put_v2_overwrites_v1_for_same_path(cache): +async def test_a_newer_hash_overwrites_the_older_for_same_path(cache): await cache.put("/lib/big.mkv", size=50_000_000, mtime=111.0, hash="full_hash", type="video", added_at=42, hash_version=1) await cache.put("/lib/big.mkv", size=50_000_000, mtime=111.0, hash="partial_hash", type="video", added_at=42, - hash_version=2) + hash_version=3) - assert await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash_version=1) is None - hit = await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0, - hash_version=2) + hit = await cache.lookup("/lib/big.mkv", size=50_000_000, mtime=111.0) assert hit is not None assert hit.hash == "partial_hash" + assert hit.hash_version == 3 @pytest.mark.asyncio @@ -191,8 +181,7 @@ async def test_v1_schema_auto_migrates(tmp_path): cache = IndexCache(db_path=db_path) await cache.open() - hit = await cache.lookup("/lib/old.mkv", size=1000, mtime=111.0, - hash_version=1) + hit = await cache.lookup("/lib/old.mkv", size=1000, mtime=111.0) await cache.close() assert hit is not None |