test_indexcache_vacuum.py

tests/test_indexcache_vacuum.py

A successful build leaves the index cache without a mostly-free file.

test_a_flush_alone_does_not_vacuum

None test_indexcache_vacuum.test_a_flush_alone_does_not_vacuum(Path tmp_path)

An aborted build (flush, no commit) does not vacuum.

tests/test_indexcache_vacuum.py:74

Show on the map →

Called by none

Calls _churn, _free_ratio

Checks

  • assert _free_ratio(path) > VACUUM_FREE_RATIO

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measured
Source · 15 lines
def test_a_flush_alone_does_not_vacuum(tmp_path: Path) -> None:
    """THE SUCCESS PATH ONLY. A VACUUM rewrites the whole file; an aborted build that paid for one
    would pay it on every retry, which is the cost the cache exists to avoid.

    @brief Free pages survive a flush.
    @return None.
    @version 1
    """
    repo = tmp_path / "repo"
    repo.mkdir()
    path = tmp_path / "clew.db.idxcache"
    cache = IndexCache(path, repo)
    _churn(cache)
    cache.close()
    assert _free_ratio(path) > VACUUM_FREE_RATIO

1 more lines, not shown

Activity · 7 steps
lines 82–82repo = tmp_path / "repo"lines 83–83repo.mkdir()lines 84–84path = tmp_path / "clew.db.idxcache"lines 85–85cache = IndexCache(path, repo)lines 86–86_churn(cache)lines 87–87cache.close()lines 88–88assert _free_ratio(path) > VACUUM_FREE_RATIO

test_a_successful_build_reclaims_a_mostly_free_cache

None test_indexcache_vacuum.test_a_successful_build_reclaims_a_mostly_free_cache(Path tmp_path)

A commit over a mostly-free cache reclaims the space.

tests/test_indexcache_vacuum.py:54

Show on the map →

Called by none

Calls _churn, _free_ratio

Checks

  • assert _free_ratio(path) > VACUUM_FREE_RATIO, "fixture did not create free pages"
  • assert _free_ratio(path) <= VACUUM_FREE_RATIO

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measured
Source · 16 lines
def test_a_successful_build_reclaims_a_mostly_free_cache(tmp_path: Path) -> None:
    """@brief Free ratio is under the threshold after commit.
    @return None.
    @version 1
    """
    repo = tmp_path / "repo"
    repo.mkdir()
    path = tmp_path / "clew.db.idxcache"
    cache = IndexCache(path, repo)
    _churn(cache)
    assert _free_ratio(path) > VACUUM_FREE_RATIO, "fixture did not create free pages"
    cache.commit()
    cache.close()
    assert _free_ratio(path) <= VACUUM_FREE_RATIO

Activity · 9 steps
lines 59–59repo = tmp_path / "repo"lines 60–60repo.mkdir()lines 61–61path = tmp_path / "clew.db.idxcache"lines 62–62cache = IndexCache(path, repo)lines 63–63_churn(cache)lines 64–64assert _free_ratio(path) > VACUUM_FREE_RATIO, "fixture did not create free pages"lines 65–65cache.commit()lines 66–66cache.close()lines 67–67assert _free_ratio(path) <= VACUUM_FREE_RATIO