test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
-92
View File
@@ -6,7 +6,6 @@ from types import SimpleNamespace
from uuid import UUID
import pytest
import requests
from tests.core.key_resolver import MemoryVault, vaults_of
from unshackle.vaults.SQLite import SQLite
@@ -94,73 +93,6 @@ def test_a_licence_clears_a_flag_of_this_run_without_a_local_vault(caplog: pytes
assert remote.told == []
def test_one_source_offered_twice_at_once_is_held_once() -> None:
"""Thread A has checked an offer and not yet stored it when thread B offers the same pair."""
a_storing, b_moved, release = threading.Event(), threading.Event(), threading.Event()
vaults = vaults_of()
source = server()
class HeldList(list):
def append(self, item: object) -> None:
if threading.current_thread().name == "a":
a_storing.set()
release.wait(10)
else:
b_moved.set()
super().append(item)
class Lock:
"""The ledger lock, which tells the test when thread B waits for it."""
def __init__(self) -> None:
self.lock = threading.Lock()
def __enter__(self) -> None:
if threading.current_thread().name == "b":
b_moved.set()
self.lock.acquire()
def __exit__(self, *exc: object) -> None:
self.lock.release()
vaults.candidates[KID] = HeldList()
vaults.lock = Lock() # type: ignore[assignment]
a = threading.Thread(target=vaults.offer, args=(KID, BAD, source), name="a")
b = threading.Thread(target=vaults.offer, args=(KID, BAD, source), name="b")
a.start()
assert a_storing.wait(10)
b.start()
assert b_moved.wait(10)
release.set()
a.join(10)
b.join(10)
assert vaults.candidates[KID] == [(BAD, source)]
def test_two_lookups_that_fail_at_once_warn_once(caplog: pytest.LogCaptureFixture) -> None:
both_asking = threading.Barrier(2, timeout=10)
class Down(MemoryVault):
def get_key(self, kid: UUID | str, service: str) -> str | None:
both_asking.wait()
raise requests.ConnectTimeout("no answer")
vaults = vaults_of(Down(local=False, name="down"))
with caplog.at_level(logging.WARNING, logger="unshackle.core.vaults"):
threads = [threading.Thread(target=vaults.get_key, args=(KID,)) for _ in range(2)]
for thread in threads:
thread.start()
for thread in threads:
thread.join(10)
messages = [record.getMessage() for record in caplog.records]
assert messages == [
"Failed to get key from Vault 'down': no answer",
"Skipping Vault 'down' for the rest of this run",
]
def test_a_licence_that_returns_the_dropped_key_warns_once_unflags_it_and_stores_it_again(
caplog: pytest.LogCaptureFixture,
) -> None:
@@ -248,19 +180,6 @@ def test_a_licence_key_is_stored_then_sent_to_the_server_vault_and_its_flag_wait
]
def test_a_vault_write_that_fails_logs_one_error_line(caplog: pytest.LogCaptureFixture) -> None:
class Failing(MemoryVault):
def is_bad_key(self, kid: UUID | str, key: str) -> bool:
raise RuntimeError("disk gone")
vaults = vaults_of(Failing())
vaults.licensed({KID: GOOD})
with caplog.at_level(logging.ERROR):
vaults.wait_writes()
assert caplog.record_tuples == [("download", logging.ERROR, "Vault write failed: RuntimeError('disk gone')")]
def test_a_proven_track_sends_one_set_to_the_server_vault_and_copies_only_its_vault_keys() -> None:
remote, local = MemoryVault({KID: GOOD}, local=False), MemoryVault(name="local")
vaults = vaults_of(local, remote)
@@ -276,14 +195,3 @@ def test_a_proven_track_sends_one_set_to_the_server_vault_and_copies_only_its_va
assert local.added == {KID: GOOD}
assert remote.added == {}
assert pushed == [({KID: GOOD, SIBLING: BAD}, "track")]
def test_building_and_dropping_many_vaults_starts_no_thread() -> None:
"""The server builds a Vaults per request; the one vault writer of the process starts only on its first write."""
before = set(threading.enumerate())
for _ in range(50):
vaults_of(MemoryVault())
assert set(threading.enumerate()) - before == set()
assert all(vaults_of().WRITER is vaults_of().WRITER for _ in range(3))