mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
test: make slow and order-dependent tests fast and independent
Slow tests: - TestPerformance inserted 10 000 records three times per backend. One test per backend now times insert, save and load on the same records, with the same assertions. - test_measurement_realtime_stream slept one second per update, 20 s per backend. The updates use synthetic timestamps one second apart in the recent past, without a pause, and send the same duplicates, out-of-order and burst writes. - test_readers_never_see_a_partial_document: the readers spun on the cache and kept the writer waiting for the GIL (~50 s). They now yield with time.sleep(0) after each lookup (~0.5 s); a non-atomic save still fails the test 10 of 10 times. - test_devicessettingsbattery.py compiled the same plain profile before each of its 235 tests. A module-scoped fixture compiles it once; a compiled profile is frozen and may be shared (20.8 s -> 9.4 s). - The --finalize case of test_geneticoptimize.py runs 250 instead of 400 generations. For this input and seed the best fitness is final in generation 213, and the solutions after 250 and 400 generations are identical field by field. The test checks the keys and the consistency of the result, not the schedule, so it detects the same as before (127 s -> 80 s on GitHub runners). test_genetic0optimize.py keeps 400. Tests that depended on another test of the same process, found by running them in another order and under pytest-xdist: - TestPredictionContainer::test_len relied on a class flag that a TestPredictionProvider fixture set and never reset. Both fixtures now set the flags with monkeypatch. - The EnergyCharts status code test got a cached response from an earlier test; it now calls _request_forecast(force_update=True) and asserts that the request was made. - test_ingress_safe_links did not wait for EOSdash, which EOS starts after its own startup. - test_forward_stream_truncates_very_long_line found the log queue left behind by test_server_start_eosdash (no worker, closed event loop). It installs its own queue now, and test_server_start_eosdash no longer leaves its queue behind. Dropping lines from a full queue was only covered through that left-over queue and gets a test of its own. Refs #1553 Co-authored-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com> Assisted-by: Claude Code (claude-opus-5-5) Assisted-by: Claude Code (claude-fable-5-2)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
SchaafAlexander
Claude Opus 5.5
parent
ce7fb96faf
commit
e2726354c2
+4
-31
@@ -834,7 +834,8 @@ class TestIntegration:
|
||||
class TestPerformance:
|
||||
"""Throughput benchmarks — not correctness tests."""
|
||||
|
||||
async def test_insert_throughput(self, config_eos, async_database_instance):
|
||||
async def test_insert_save_load_throughput(self, config_eos, async_database_instance):
|
||||
"""Insert, save and load the same records; each phase is timed on its own."""
|
||||
sequence = SampleDataSequence()
|
||||
await _reset_sequence_state(sequence)
|
||||
base_time = to_datetime("2024-01-01T00:00:00Z")
|
||||
@@ -854,42 +855,14 @@ class TestPerformance:
|
||||
|
||||
assert len(sequence.records) == n
|
||||
|
||||
async def test_save_throughput(self, config_eos, async_database_instance):
|
||||
sequence = SampleDataSequence()
|
||||
await _reset_sequence_state(sequence)
|
||||
base_time = to_datetime("2024-01-01T00:00:00Z")
|
||||
n = 10_000
|
||||
|
||||
for i in range(n):
|
||||
await sequence.db_insert_record(
|
||||
SampleDataRecord(
|
||||
date_time=base_time.add(minutes=i),
|
||||
temperature=20.0 + (i % 100) * 0.1,
|
||||
)
|
||||
)
|
||||
|
||||
start = time.perf_counter()
|
||||
saved = await sequence.db_save_records()
|
||||
save_duration = time.perf_counter() - start
|
||||
|
||||
assert saved == n
|
||||
print(f"\nSaved {n} records in {save_duration:.2f}s "
|
||||
print(f"Saved {n} records in {save_duration:.2f}s "
|
||||
f"({n / save_duration:.0f} rec/s)")
|
||||
|
||||
async def test_load_throughput(self, config_eos, async_database_instance):
|
||||
sequence = SampleDataSequence()
|
||||
await _reset_sequence_state(sequence)
|
||||
base_time = to_datetime("2024-01-01T00:00:00Z")
|
||||
n = 10_000
|
||||
|
||||
for i in range(n):
|
||||
await sequence.db_insert_record(
|
||||
SampleDataRecord(
|
||||
date_time=base_time.add(minutes=i),
|
||||
temperature=20.0 + (i % 100) * 0.1,
|
||||
)
|
||||
)
|
||||
await sequence.db_save_records()
|
||||
await _reset_sequence_state(sequence)
|
||||
|
||||
start = time.perf_counter()
|
||||
@@ -897,7 +870,7 @@ class TestPerformance:
|
||||
load_duration = time.perf_counter() - start
|
||||
|
||||
assert loaded == n
|
||||
print(f"\nLoaded {n} records in {load_duration:.2f}s "
|
||||
print(f"Loaded {n} records in {load_duration:.2f}s "
|
||||
f"({n / load_duration:.0f} rec/s)")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user