-
Notifications
You must be signed in to change notification settings - Fork 403
Add unit tests for LocalPush reconnection logic #4133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: local-push
Are you sure you want to change the base?
Conversation
|
@copilot your PR is empty |
Tests cover: - Reconnection backoff delay behavior (5s, 10s, 30s cap) - Timer cancellation when servers reconnect - State tracking of disconnected servers - Rapid disconnection/reconnection events - Multiple servers disconnecting simultaneously - Edge cases (inactive managers, partial reconnection) Note: Tests document expected behavior but are limited by NetworkExtension framework constraints. The reconnection timer and attempt counter are private and tested via observable behavior. Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
- Add DEBUG-only test accessors to NotificationManagerLocalPushInterfaceExtension - Rewrite tests to use test accessors for direct state verification - Add tests for backoff delay calculation and timer state - Add tests for attempt counter increment and reset - Add tests for rapid schedule/cancel cycles - Document integration behavior and expected reconnection flow Tests now directly verify: - Reconnection delays array (5s, 10s, 30s) - Timer creation and cancellation - Attempt counter behavior - State transitions during reconnection - Edge cases like multiple attempts Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
I've added comprehensive unit tests for the LocalPush reconnection logic. The PR now includes:
|
|
Found 37 unused localization strings in the codebase. Click to see detailsConsider running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive unit tests for the LocalPush reconnection logic introduced in PR #4113. The tests cover exponential backoff delays, timer cancellation, state transitions, and various edge cases to ensure the reconnection mechanism works correctly.
- Added 13 focused test cases verifying private reconnection state and behavior
- Introduced DEBUG-only test accessors to expose internal state without compromising production code
- Tests validate backoff calculation (5s, 10s, 30s cap), timer lifecycle, attempt counter behavior, and rapid state changes
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Tests/App/NotificationManagerLocalPushInterfaceExtension.test.swift | New test file with 13 test cases covering reconnection logic, backoff delays, timer management, and edge cases |
| Sources/App/Notifications/NotificationManagerLocalPushInterfaceExtension.swift | Added DEBUG-only extension with test accessors for internal state (reconnection attempt, timer status, disconnected servers, delays) and test methods to trigger reconnection operations |
| HomeAssistant.xcodeproj/project.pbxproj | Added test file to project build configuration and corrected SharedPush package path references |
| @testable import Shared | ||
| import XCTest | ||
|
|
||
| class NotificationManagerLocalPushInterfaceExtensionTests: XCTestCase { |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class declaration should use 'final' instead of just 'class' to follow Swift best practices and match the pattern used in other test files in this codebase (e.g., AssistViewModelTests, WindowScenesManagerTests). This prevents unintended subclassing and can provide minor performance improvements.
| class NotificationManagerLocalPushInterfaceExtensionTests: XCTestCase { | |
| final class NotificationManagerLocalPushInterfaceExtensionTests: XCTestCase { |
Summary
Adds comprehensive unit tests for the reconnection logic introduced in PR #4113, covering backoff delays, timer cancellation, state transitions, and edge cases with rapid disconnect/reconnect events.
Screenshots
N/A - Test coverage only
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
This PR addresses feedback from the code review on #4113 requesting test coverage for the
scheduleReconnection(),attemptReconnection(), andcancelReconnection()methods.Implementation approach:
NotificationManagerLocalPushInterfaceExtensionto expose internal state for verification without compromising production codeTest coverage includes:
Note: Due to NetworkExtension framework constraints (NEAppPushManager requires provisioning/entitlements), full integration testing requires Xcode environment. The unit tests verify all testable logic through internal accessors.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.