Commit graph

3 commits

Author SHA1 Message Date
torlando-tech
1e49178c3e test: use real BLEInterface instances for coverage tracking
Replace Mock-based fixtures with real BLEInterface instances in
stale identity check tests. This ensures coverage.py properly
tracks execution of production code paths.

The Mock approach with method binding executed the production code
but coverage tracking was inconsistent. Using real instances
guarantees proper coverage attribution.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 15:04:08 -05:00
torlando-tech
5c9ceb28f8 test: add coverage for stale identity check paths in _check_duplicate_identity
Add tests covering previously uncovered code paths:
- Pending detach check (Check 1) allowing reconnection
- Not-connected check (Check 2) allowing reconnection
- Exception handling when zombie disconnect fails

Improves patch coverage for PR #38 from 48.57% to full coverage
of the _check_duplicate_identity changes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 14:46:08 -05:00
torlando-tech
73be6d93c0 feat: add zombie connection detection to break symmetric deadlock
When BLE link degrades, 1-byte keepalives may still work while larger data
packets fail. Both sides think the connection is "alive" based on keepalives,
but data can't flow. This causes a deadlock where new connections are
rejected as "duplicates" even though the existing connection is non-functional.

This change adds zombie detection by tracking when real data (not keepalives)
was last received. If an existing connection has only exchanged keepalives
for > 30 seconds (configurable via _zombie_timeout), new connections from
the same identity are allowed and the zombie connection is disconnected.

Changes:
- Add _last_real_data dict to track last real data timestamp per identity
- Add _zombie_timeout (default 30s) for configurable zombie threshold
- Update _check_duplicate_identity with Check 3: zombie detection
- Update _handle_ble_data to track real data activity after keepalive filter
- Initialize tracking in _handle_identity_handshake and _spawn_peer_interface
- Clean up tracking in _process_pending_detaches
- Add comprehensive test suite for zombie detection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 12:47:45 -05:00