Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to Lumen will be documented in this file.
- Speed up slow `lumen.sh` device-flow and stream-disconnect tests.
- Speed up the test suite: skip real sleeps in all `lumen.sh` tests, clone per-module PostgreSQL test databases from one migrated template, and drop the per-migration upgrade/downgrade tests for already-released migrations. (#234)
- Tests now verify that API-key hashes are keyed on `ENCRYPTION_KEY` (#164).
- Tests now pin that a coin balance refilled exactly one hour ago is refilled on the next pass. (#312)
- `LUMEN_WSGI_WORKERS` now defaults to `auto`, sized at 2× DB pool capacity (10–256); Helm `wsgiWorkers` defaults to `"auto"` (#238).
- OAuth key requests that replace an existing key now refresh its secret in place, keeping its name and usage stats, instead of revoking it. (#182)

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_token_refill.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def test_refills_after_full_hour(app, test_user):
assert bal.last_refill_at == now


def test_refills_at_exact_one_hour_boundary(app, test_user):
with app.app_context():
from lumen.extensions import db
from lumen.models.entity_balance import EntityBalance
from lumen.services.token_refill import refill_coin_balances
now = datetime.now(timezone.utc).replace(tzinfo=None)
_add_limit(db, test_user["id"], max_coins=100, refresh_coins=10)
_add_balance(db, test_user["id"], coins_left=50,
last_refill_at=now - timedelta(hours=1))
db.session.commit()

assert refill_coin_balances(now=now) == 1
bal = db.session.execute(select(EntityBalance).filter_by(entity_id=test_user["id"])).scalar_one_or_none()
assert float(bal.coins_left) == 60.0 # 50 + 1*10
assert bal.last_refill_at == now


def test_refill_capped_at_max_coins(app, test_user):
with app.app_context():
from lumen.extensions import db
Expand Down
Loading