Add personal notes, DeepSearch history, backup offload, and gateway auth throttling
DevPlace CI / test (push) Failing after 28m20s
DevPlace CI / test (push) Failing after 28m20s
Also streamline the top navigation: drop the Tools dropdown, make Quizzes and Battles icon-only entries, and remove the Workspace, Containers and Editor entry points from the project detail page.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.services.backup import service, store
|
||||
|
||||
|
||||
def _stats(used_percent):
|
||||
return {
|
||||
"disk": {
|
||||
"total_bytes": 100,
|
||||
"used_bytes": used_percent,
|
||||
"free_bytes": 100 - used_percent,
|
||||
"total_human": "100 B",
|
||||
"used_human": f"{used_percent} B",
|
||||
"free_human": f"{100 - used_percent} B",
|
||||
"used_percent": used_percent,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _disk(used_percent):
|
||||
return _stats(used_percent)["disk"]
|
||||
|
||||
|
||||
def test_check_disk_usage_warns_once_and_recovers_once(local_db, monkeypatch):
|
||||
svc = service.BackupService()
|
||||
assert svc.disk_warn_percent_field.default == service.DEFAULT_DISK_WARN_PERCENT
|
||||
logs = []
|
||||
monkeypatch.setattr(svc, "log", lambda message: logs.append(message))
|
||||
|
||||
monkeypatch.setattr(store, "disk_usage", lambda: _disk(50))
|
||||
svc._check_disk_usage()
|
||||
assert logs == []
|
||||
assert svc._disk_warned is False
|
||||
|
||||
monkeypatch.setattr(store, "disk_usage", lambda: _disk(95))
|
||||
svc._check_disk_usage()
|
||||
assert len(logs) == 1
|
||||
assert "critical" in logs[0].lower()
|
||||
assert svc._disk_warned is True
|
||||
|
||||
svc._check_disk_usage()
|
||||
assert len(logs) == 1
|
||||
|
||||
monkeypatch.setattr(store, "disk_usage", lambda: _disk(40))
|
||||
svc._check_disk_usage()
|
||||
assert len(logs) == 2
|
||||
assert "under threshold" in logs[1].lower()
|
||||
assert svc._disk_warned is False
|
||||
|
||||
|
||||
def test_collect_metrics_includes_disk_usage_stat(local_db, monkeypatch):
|
||||
svc = service.BackupService()
|
||||
monkeypatch.setattr(store, "disk_usage", lambda: _disk(62))
|
||||
|
||||
metrics = svc.collect_metrics()
|
||||
|
||||
labels = [stat["label"] for stat in metrics["stats"]]
|
||||
assert "Disk usage" in labels
|
||||
disk_stat = next(stat for stat in metrics["stats"] if stat["label"] == "Disk usage")
|
||||
assert "62%" in disk_stat["value"]
|
||||
|
||||
|
||||
def test_collect_metrics_never_walks_storage_tree(local_db, monkeypatch):
|
||||
svc = service.BackupService()
|
||||
monkeypatch.setattr(store, "disk_usage", lambda: _disk(10))
|
||||
|
||||
def boom():
|
||||
raise AssertionError("compute_storage_stats must not run on the service tick")
|
||||
|
||||
monkeypatch.setattr(store, "compute_storage_stats", boom)
|
||||
svc.collect_metrics()
|
||||
svc._check_disk_usage()
|
||||
Reference in New Issue
Block a user