Skip to content

Make test_database persist last_seen it checks - #1901

Draft
TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/fix-test-database-last-seen
Draft

TheJulianJES wants to merge 1 commit into
devfrom
zigpy-bot/fix-test-database-last-seen

Conversation

@TheJulianJES

Copy link
Copy Markdown
Contributor

Fixes test failure seen in https://github.com/zigpy/zigpy/actions/runs/37516303325/job/112450383118?pr=1900 and actually makes the test work and test last_seen being written.

Changes

test_database failed on a CI runner for #1900 with assert abs(dev.last_seen - dev_last_seen) < 0.01 (10.8 ms), although nothing in that PR touches this path.

The cause is in the test: _save_device_last_seen only writes a new last_seen when it is more than MIN_UPDATE_DELTA (30 s) newer than the stored value. The test sets last_seen to the current time, so the update is never written, and the reloaded value is the device's earlier save time. The 10 ms tolerance therefore measured how long that stretch of the test took. Locally it is about 1 ms on both dev and #1900; a slow runner can exceed 10 ms.

The test now sets last_seen past the throttle, so the update is persisted and the reloaded value matches exactly (0 ms difference). It also covers the write path now: with device_last_seen_updated() disabled, the old test still passed, while the new one fails.

`_save_device_last_seen` skips updates within `MIN_UPDATE_DELTA` (30 s) of
the stored value, so setting `last_seen` to the current time was never
written. The reloaded value was the device's earlier save time, and the
10 ms tolerance only measured how fast the test ran, which failed on a slow
CI runner. Set it past the throttle so the update is actually persisted and
checked.
@TheJulianJES
TheJulianJES requested a balanced review from Copilot October 6, 2026 19:26
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.51%. Comparing base (b4543ff) to head (fa7cdd0).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1901   +/-   ##
=======================================
  Coverage   99.51%   99.51%           
=======================================
  Files          61       61           
  Lines       12773    12773           
=======================================
  Hits        12711    12711           
  Misses         62       62           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused test correction accurately accounts for the persistence throttle and prevents timing-dependent results.

Review effort: Balanced
Findings: None

What changed in this PR

Updates test_database to reliably exercise persistence of throttled last_seen updates.

Changes:

  • Advances the test timestamp beyond MIN_UPDATE_DELTA.
  • Documents why the future timestamp is necessary.
File Description
tests/​test_appdb.py Ensures the database write path for last_seen is tested reliably.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvement to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants