[MM-62924] WebSocketClient reconnection unit tests (#30135)

This commit adds some reconnection-specific unit tests to the WebSocketClient class, and fixes a few minor bugs:

- If `close()` is called during a reconnection delay, the socket won't close.
- If `send()` is called during a reconnection delay, we immediately try to reconnect (and don't respect any configured delays).
- If `initialize()` is called during a reconnection delay, we immediately try to reconnect (and don't respect any configured delays).
- If we receive two disconnection events, we'll attempt to reconnect with two new connections.

To allow for testing, I also needed to make the WebSocketClient more configurable. Specifically, the config allows for mocking the underlying websockets, and to control timeout delays.
Этот коммит содержится в:
David Krauser
2025-02-20 13:54:18 -05:00
коммит произвёл GitHub
родитель 9e47f2ef0c
Коммит 1dbd1fa4db
3 изменённых файлов: 287 добавлений и 19 удалений

Просмотреть файл

@@ -99,6 +99,13 @@ exports[`PostBodyAdditionalContent with a normal link Should render the plugin c
WebSocketClient {
"closeCallback": null,
"closeListeners": Set {},
"config": Object {
"maxWebSocketFails": 7,
"maxWebSocketRetryTime": 300000,
"minWebSocketRetryTime": 3000,
"newWebSocketFn": [Function],
"reconnectJitterRange": 2000,
},
"conn": null,
"connectFailCount": 0,
"connectionId": "",
@@ -114,6 +121,7 @@ exports[`PostBodyAdditionalContent with a normal link Should render the plugin c
"postedAck": false,
"reconnectCallback": null,
"reconnectListeners": Set {},
"reconnectTimeout": null,
"responseCallbacks": Object {},
"responseSequence": 1,
"serverHostname": "",
@@ -147,6 +155,13 @@ exports[`PostBodyAdditionalContent with a normal link Should render the plugin c
WebSocketClient {
"closeCallback": null,
"closeListeners": Set {},
"config": Object {
"maxWebSocketFails": 7,
"maxWebSocketRetryTime": 300000,
"minWebSocketRetryTime": 3000,
"newWebSocketFn": [Function],
"reconnectJitterRange": 2000,
},
"conn": null,
"connectFailCount": 0,
"connectionId": "",
@@ -162,6 +177,7 @@ exports[`PostBodyAdditionalContent with a normal link Should render the plugin c
"postedAck": false,
"reconnectCallback": null,
"reconnectListeners": Set {},
"reconnectTimeout": null,
"responseCallbacks": Object {},
"responseSequence": 1,
"serverHostname": "",