tests.test_cache moduleΒΆ

tests.test_cache.count_hashes(monkeypatch)[source]ΒΆ

Counts the mails actually hashed, which a cache hit must not be.

Restoring a mail from the cache skips its parsing entirely, so hash_key() is the sharpest signal that the file was read rather than served from the database.

tests.test_cache.cache_db(tmp_path)[source]ΒΆ

Path of the hash cache database of a test.

tests.test_cache.cached_run(invoke, cache_db)[source]ΒΆ

Runs DEDUP_ARGS with the hash cache of the test.

Takes the options to add, then the boxes to deduplicate.

tests.test_cache.test_cache_is_off_by_default(invoke, make_box, tmp_path, monkeypatch)[source]ΒΆ

No database is created unless the user opts in.

tests.test_cache.test_default_cache_dir(monkeypatch, platform, xdg_cache_home, local_app_data, expected)[source]ΒΆ

The locations docs/performance.md lists for each platform.

click-extra tests the edge cases of get_cache_dir(), like a relative XDG_CACHE_HOME.

tests.test_cache.test_default_cache_path_sits_under_the_cache_dir()[source]ΒΆ

The database lands in the platform’s cache location, not next to the mails.

tests.test_cache.test_warm_run_matches_uncached_run(invoke, cached_run, make_box, box_format, jobs, count_hashes)[source]ΒΆ

A run served from the cache must decide exactly what an uncached run does.

The report accounts for every mail through the four steps, so a stale hash would surface as a different grouping and different metrics. Swept over every format, as each one locates its mails differently, and over the sequential and parallel hashing paths, as only the former reads the cache one mail at a time.

tests.test_cache.test_settings_change_discards_the_cache(cached_run, make_box, count_hashes, changed_option)[source]ΒΆ

Every option feeding a cached value invalidates the whole database.

An entry produced under different hashing settings cannot be told apart from a valid one by its staleness key alone, so none of them may survive.

tests.test_cache.test_modified_mail_is_rehashed(cached_run, make_box, count_hashes)[source]ΒΆ

A mail whose file changed must not be served from the cache.

Maildir keys survive a rewrite, so only the staleness key stands between a modified mail and a hash computed from its previous content.

tests.test_cache.test_edited_file_based_box_invalidates_every_mail(cached_run, make_box, count_hashes)[source]ΒΆ

Editing an mbox invalidates all of its mails, not just the ones that moved.

Mails of an mbox share the box’s file and are keyed by byte offsets, which shift as soon as a mail is added or removed.

tests.test_cache.test_mail_vanishing_mid_run_is_rejected(invoke, make_box, cache_db, monkeypatch, cache_args)[source]ΒΆ

A mail removed between the box listing it and the run reading it is rejected.

Regression test: the hashing step used to walk the box with iteritems(), which swallows that race. Walking the keys instead, so a cached mail is never read, has to keep handling it rather than dying on a KeyError. Rejecting the mail keeps it in the statistics, as a --jobs worker does for a file that is gone.

tests.test_cache.test_unusable_cache_does_not_abort_the_run(invoke, make_box, tmp_path)[source]ΒΆ

A database that cannot be opened is reported and skipped.

The cache only ever saves work, so an unwritable location, a read-only home or a full disk must not take the deduplication down with it.

tests.test_cache.test_corrupt_cache_is_skipped_and_closed(cached_run, cache_db, make_box, monkeypatch)[source]ΒΆ

A file that is not a database is reported and skipped.

Its connection is closed.

SQLite opens any file, and only fails on the first statement it runs there, so the connection exists by then and must not stay open for the rest of the run.

tests.test_cache.test_unhashed_mails_are_not_cached(invoke, make_box, cache_db)[source]ΒΆ

A mail with too few headers has no hash to store, so it is read every run.

tests.test_cache.cached_rows(cache_db)[source]ΒΆ

Number of mail entries held by a cache database.

The connection of sqlite3 commits on leaving a with block, but stays open: closing() is what closes it.

Return type:

int

tests.test_cache.test_deleted_mails_are_pruned(cached_run, cache_db, make_box, monkeypatch, write_batch)[source]ΒΆ

Mails removed from a box must not keep their entry forever.

A cache nobody prunes only grows, holding hashes for mails that no longer exist. Batches of one flush the writes and the sightings of a run as they come, as a corpus bigger than a batch does.

tests.test_cache.test_vanished_box_is_pruned(cached_run, cache_db, make_box)[source]ΒΆ

A box that was deleted or moved takes all of its entries with it.

tests.test_cache.test_unvisited_boxes_are_left_alone(cached_run, cache_db, make_box)[source]ΒΆ

Only the boxes a run opens are pruned mail by mail.

Every mail of a box nobody opened is absent from the run’s sightings for the plain reason that nobody looked, which is no evidence that it is gone. Pruning on that basis would empty the cache of every box not passed on the command line.

tests.test_cache.test_run_survives_a_database_held_by_another_run(cached_run, cache_db, make_box)[source]ΒΆ

A database another run is writing must not take this one down.

Runs sharing a cache contend on the write burst each performs at the end. By then the deduplication is done, so losing that race may only cost the next run its head start. Simulated by holding the write lock for longer than the loser is willing to wait.

tests.test_cache.test_cache_survives_a_corpus_growing_between_runs(cached_run, make_box)[source]ΒΆ

Mails added to a folder-based box after a run join the cached ones.