Skip to content

test: add unit coverage for subscribe_ais_stream, position cache, and get_vessel error paths#2004

Merged
jomcgi merged 5 commits intomainfrom
test/ships-backend-coverage
Apr 11, 2026
Merged

test: add unit coverage for subscribe_ais_stream, position cache, and get_vessel error paths#2004
jomcgi merged 5 commits intomainfrom
test/ships-backend-coverage

Conversation

@jomcgi
Copy link
Copy Markdown
Owner

@jomcgi jomcgi commented Apr 11, 2026

Summary

  • Adds TestSubscribeAisStreamUnit class to unit_test.py covering subscribe_ais_stream() — the service's core NATS loop — with 14 new tests for batch processing, deduplication counter, ack-after-commit, WebSocket broadcast, catchup detection, error recovery, and batch-size selection
  • Adds TestDatabaseLoadPositionCacheNonEmpty with 3 tests for _load_position_cache() against a pre-populated DB, including reconnect cache rebuild and first_seen_at_location preservation
  • Adds TestDatabaseCleanupOldPositionsMultiBatch with 4 tests exercising the while True batch-delete loop continuation path in cleanup_old_positions()
  • Adds TestGetVesselErrorBranches with 4 tests covering get_vessel() analytics error paths: missing vessel, valid first_seen, malformed first_seen (ValueError branch), and NULL first_seen (no time fields added)

Test plan

  • CI passes //projects/ships/backend/tests:unit_test
  • No production code modified — only projects/ships/backend/tests/unit_test.py changed

🤖 Generated with Claude Code

… get_vessel error paths

Fills four coverage gaps in unit_test.py:
- subscribe_ais_stream(): batch processing, dedup counter, acks, WS
  broadcast, catchup detection, error handling, batch-size selection
- Database._load_position_cache: non-empty DB reconnect, first_seen
  preservation, empty-table baseline
- cleanup_old_positions: multi-batch loop continuation and partial-batch exit
- get_vessel: invalid/missing first_seen_at_location error branches

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jomcgi jomcgi enabled auto-merge (rebase) April 11, 2026 04:49
@jomcgi jomcgi disabled auto-merge April 11, 2026 04:51
claude and others added 2 commits April 10, 2026 22:00
The test was using a hardcoded timestamp from 2024-03-01 which is
well outside the 7-day retention window, causing the position to be
deleted and the assertion to fail. Replace with datetime.now() so
the timestamp is always within the retention window.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jomcgi jomcgi merged commit f72a59c into main Apr 11, 2026
6 checks passed
@jomcgi jomcgi deleted the test/ships-backend-coverage branch April 11, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants