Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

dbbasic-object-server/tests/test_object_metrics_history.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
test_object_metrics_history.py · 1.7 KB · 58 lines
1"""Tests for TSV-backed metrics history snapshots."""
2
3import object_metrics_history
4
5
6def test_append_and_read_round_trip(tmp_path):
7 object_metrics_history.append_snapshot(
8 {
9 "uptime_seconds": 120.5,
10 "requests": 42,
11 "errors": 1,
12 "rps": 0.35,
13 "error_rate": 2.38,
14 "p50_ms": 9.1,
15 "p95_ms": 40.2,
16 "cpu_percent": 3.5,
17 "memory_used_percent": 41.0,
18 "disk_used_percent": 20.3,
19 },
20 base_dir=tmp_path,
21 )
22 object_metrics_history.append_snapshot(
23 {"requests": 50, "errors": 1, "rps": 0.4},
24 base_dir=tmp_path,
25 )
26
27 rows = object_metrics_history.read_history(base_dir=tmp_path)
28
29 assert len(rows) == 2
30 assert rows[0]["requests"] == 42
31 assert rows[0]["p95_ms"] == 40.2
32 assert rows[0]["timestamp"].endswith("Z")
33 assert rows[1]["requests"] == 50
34 assert rows[1]["cpu_percent"] is None
35
36
37def test_history_is_capped_to_max_rows(tmp_path):
38 for index in range(8):
39 object_metrics_history.append_snapshot(
40 {"requests": index},
41 base_dir=tmp_path,
42 max_rows=5,
43 )
44
45 rows = object_metrics_history.read_history(base_dir=tmp_path)
46
47 assert len(rows) == 5
48 assert [row["requests"] for row in rows] == [3, 4, 5, 6, 7]
49
50
51def test_read_history_respects_limit_and_missing_file(tmp_path):
52 assert object_metrics_history.read_history(base_dir=tmp_path) == []
53
54 for index in range(5):
55 object_metrics_history.append_snapshot({"requests": index}, base_dir=tmp_path)
56
57 rows = object_metrics_history.read_history(base_dir=tmp_path, limit=2)
58 assert [row["requests"] for row in rows] == [3, 4]