fix(llc): fix connecting while connecting and disconneting (#1237)
* fix(llc): fix connecting while connecting and disconneting * chore(llc): update changelog * chore(llc): add test * chore(llc): improve test * fix(llc): _resetRequestFlags regardless of the connection status
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
## Upcoming
|
||||||
|
|
||||||
|
🐞 Fixed
|
||||||
|
|
||||||
|
- Fix WebSocket contemporary connection calls while disconnecting
|
||||||
|
|
||||||
## 4.3.0
|
## 4.3.0
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
@@ -436,6 +436,9 @@ class WebSocket with TimerHelper {
|
|||||||
/// Disconnects the WS and releases eventual resources
|
/// Disconnects the WS and releases eventual resources
|
||||||
void disconnect() {
|
void disconnect() {
|
||||||
if (connectionStatus == ConnectionStatus.disconnected) return;
|
if (connectionStatus == ConnectionStatus.disconnected) return;
|
||||||
|
|
||||||
|
_resetRequestFlags(resetAttempts: true);
|
||||||
|
|
||||||
_connectionStatus = ConnectionStatus.disconnected;
|
_connectionStatus = ConnectionStatus.disconnected;
|
||||||
|
|
||||||
_logger?.info('Disconnecting web-socket connection');
|
_logger?.info('Disconnecting web-socket connection');
|
||||||
@@ -447,6 +450,7 @@ class WebSocket with TimerHelper {
|
|||||||
_stopMonitoringEvents();
|
_stopMonitoringEvents();
|
||||||
|
|
||||||
_manuallyClosed = true;
|
_manuallyClosed = true;
|
||||||
|
|
||||||
_closeWebSocketChannel();
|
_closeWebSocketChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,40 @@ void main() {
|
|||||||
addTearDown(timer.cancel);
|
addTearDown(timer.cancel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('`connect`, `disconnect` and `connect` again without waiting', () async {
|
||||||
|
final user = OwnUser(
|
||||||
|
id: 'test-user',
|
||||||
|
name: 'test',
|
||||||
|
);
|
||||||
|
const connectionId = 'test-connection-id';
|
||||||
|
// Sends connect event to web-socket stream
|
||||||
|
final timer = Timer.periodic(const Duration(milliseconds: 300), (_) {
|
||||||
|
final event = Event(
|
||||||
|
type: EventType.healthCheck,
|
||||||
|
connectionId: connectionId,
|
||||||
|
me: user,
|
||||||
|
);
|
||||||
|
webSocketSink.add(json.encode(event));
|
||||||
|
});
|
||||||
|
|
||||||
|
await webSocket.connect(
|
||||||
|
user,
|
||||||
|
);
|
||||||
|
|
||||||
|
webSocket
|
||||||
|
..disconnect()
|
||||||
|
..connect(user)
|
||||||
|
..disconnect();
|
||||||
|
final event = await webSocket.connect(user);
|
||||||
|
|
||||||
|
expect(event.type, EventType.healthCheck);
|
||||||
|
expect(event.connectionId, connectionId);
|
||||||
|
expect(event.me, isNotNull);
|
||||||
|
expect(event.me!.id, user.id);
|
||||||
|
|
||||||
|
addTearDown(timer.cancel);
|
||||||
|
});
|
||||||
|
|
||||||
test('`connect` should throw if already in connection attempt', () async {
|
test('`connect` should throw if already in connection attempt', () async {
|
||||||
final user = OwnUser(id: 'test-user');
|
final user = OwnUser(id: 'test-user');
|
||||||
webSocket.connect(user);
|
webSocket.connect(user);
|
||||||
|
|||||||
Reference in New Issue
Block a user