rdkcentral / mock-firebolt

An advanced, controllable mock Firebolt OS implementation, which can also act as a reverse proxy to a real Firebolt OS running on a real device
Apache License 2.0
4 stars 21 forks source link

Remove stale ws connections from user2ws map when connection is closed #153

Closed ksentak closed 6 months ago

ksentak commented 6 months ago

Enhancements to WebSocket Connection Management and Unit Tests

Summary:

This pull request introduces improvements to the existing WebSocket (ws) connection management and functional unit tests. Key changes include:

WebSocket Connection Cleanup: I've extended the current functionality that monitors and terminates stale ws connections. Now, when a ws connection is closed—whether due to inactivity or explicitly by a user—it's also removed from the user2ws map. This map maintains a record of active ws connections for each user, ensuring the list remains accurate and up-to-date.

Unit Test Refactoring: A failing functional unit test caused by the above changes highlighted an issue where WebSocket connections were closed immediately after message receipt, hindering subsequent commands within the same test scenario. To address this, I refactored the existing function-based approach into a more robust class. This class establishes a WebSocket connection and provides methods for sending commands and closing the ws connection. This enhancement simplifies test scenarios involving multiple commands and avoids the overhead of repeatedly opening and closing connections.