Tests: reuse a pool of RSA keys
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 1m51s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 1m51s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
Generating 2048-bit keys for every sharing user and scripted remote account dominated federation test time. Tests only need distinct valid keys, so an autouse fixture hands out a pool of 16 generated once per run (50s -> 40s for the suite). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
f312c4b577
commit
5897e8217f
1 file changed
+30
@@ -242,3 +242,33 @@ def remote():
|
||||
server = FakeRemote()
|
||||
yield server
|
||||
server.close()
|
||||
|
||||
|
||||
# --- Fast RSA keys --------------------------------------------------------------------------
|
||||
# Generating 2048-bit keys dominates federation test time. Tests only need distinct valid
|
||||
# keys, so hand out a pool generated once per run (cycling; 16 is plenty per test).
|
||||
|
||||
_KEY_POOL: list = []
|
||||
|
||||
|
||||
def _pooled_rsa_key(public_exponent=65537, key_size=2048, backend=None):
|
||||
|
||||
if len(_KEY_POOL) < 16:
|
||||
_KEY_POOL.append(_ORIGINAL_GENERATE(public_exponent=public_exponent, key_size=key_size))
|
||||
return _KEY_POOL[-1]
|
||||
_KEY_POOL.append(_KEY_POOL.pop(0))
|
||||
return _KEY_POOL[-1]
|
||||
|
||||
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa as _rsa_module # noqa: E402
|
||||
|
||||
_ORIGINAL_GENERATE = _rsa_module.generate_private_key
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _fast_rsa_keys(monkeypatch):
|
||||
import federation_helpers
|
||||
from scrobbler.federation import keys as federation_keys
|
||||
|
||||
monkeypatch.setattr(federation_keys.rsa, "generate_private_key", _pooled_rsa_key)
|
||||
monkeypatch.setattr(federation_helpers.rsa, "generate_private_key", _pooled_rsa_key)
|
||||
Reference in new issue
Block a user