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:
committed by
GitHub
parent
d2883c87f0
commit
a37bf2bde4
@@ -1,3 +1,9 @@
|
||||
## Upcoming
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
- Fix WebSocket contemporary connection calls while disconnecting
|
||||
|
||||
## 4.3.0
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
@@ -436,6 +436,9 @@ class WebSocket with TimerHelper {
|
||||
/// Disconnects the WS and releases eventual resources
|
||||
void disconnect() {
|
||||
if (connectionStatus == ConnectionStatus.disconnected) return;
|
||||
|
||||
_resetRequestFlags(resetAttempts: true);
|
||||
|
||||
_connectionStatus = ConnectionStatus.disconnected;
|
||||
|
||||
_logger?.info('Disconnecting web-socket connection');
|
||||
@@ -447,6 +450,7 @@ class WebSocket with TimerHelper {
|
||||
_stopMonitoringEvents();
|
||||
|
||||
_manuallyClosed = true;
|
||||
|
||||
_closeWebSocketChannel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,40 @@ void main() {
|
||||
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 {
|
||||
final user = OwnUser(id: 'test-user');
|
||||
webSocket.connect(user);
|
||||
|
||||
Reference in New Issue
Block a user