Skip to content

Commit

Permalink
fixup! TF-3334 Add more concurrence test cases for WebSocketQueueHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Dec 24, 2024
1 parent 8487a68 commit d9a1bb1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ class WebSocketQueueHandler {
return;
}

if (queueSize >= _maxQueueSize) {
log('WebSocketQueueHandler::enqueue:Queue full, removing oldest message');
_messageQueue.removeFirst();
try {
if (queueSize >= _maxQueueSize) {
log('WebSocketQueueHandler::enqueue:Queue full, removing oldest message');
_messageQueue.removeFirst();
}
} catch (e) {
logError('WebSocketQueueHandler::enqueue:Exception = $e');
}

log('WebSocketQueueHandler::enqueue(): ${message.id}');
Expand Down Expand Up @@ -81,29 +85,39 @@ class WebSocketQueueHandler {

void _addToProcessedMessages(String messageId) {
log('WebSocketQueueHandler::_addToProcessedMessages(): adding message $messageId to processed messages');
if (_processedMessageIds.length >= _maxProcessedIdsSize) {
_processedMessageIds.removeFirst();
try {
if (_processedMessageIds.length >= _maxProcessedIdsSize) {
_processedMessageIds.removeFirst();
}
} catch (e) {
logError('WebSocketQueueHandler::_addToProcessedMessages:Exception = $e');
}

_processedMessageIds.add(messageId);
}

void removeMessagesUpToCurrent(String messageId) {
log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing messages up to $messageId');
final isCurrentStateExist = _messageQueue
.any((message) => message.id == messageId);
try {
log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing messages up to $messageId');
final isCurrentStateExist = _messageQueue
.any((message) => message.id == messageId);

if (!isCurrentStateExist) {
log('WebSocketQueueHandler::removeMessagesUpToCurrent:Current state $messageId not found in the queue.');
return;
}
while (queueSize > 0) {
final removedMessage = _messageQueue.removeFirst();
log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing message ${removedMessage.id} up to $messageId');
if (removedMessage.id == messageId) {
break;
if (!isCurrentStateExist) {
log('WebSocketQueueHandler::removeMessagesUpToCurrent:Current state $messageId not found in the queue.');
return;
}

while (queueSize > 0) {
final removedMessage = _messageQueue.removeFirst();
log('WebSocketQueueHandler::removeMessagesUpToCurrent(): removing message ${removedMessage.id} up to $messageId');
if (removedMessage.id == messageId) {
break;
}
}
log('WebSocketQueueHandler::removeMessagesUpToCurrent:Updated Queue: $queueSize');
} catch (e) {
logError('WebSocketQueueHandler::removeMessagesUpToCurrent:Exception = $e');
}
log('WebSocketQueueHandler::removeMessagesUpToCurrent:Updated Queue: $queueSize');
}

@visibleForTesting
Expand Down
3 changes: 2 additions & 1 deletion lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ class ThreadController extends BaseController with EmailActionController {
return Future.value();
}

if (searchController.isSearchEmailRunning) {
if (searchController.isSearchEmailRunning &&
mailboxDashBoardController.dashboardRoute.value == DashboardRoutes.thread) {
await _refreshChangeSearchEmail();
} else {
await _refreshChangeListEmail();
Expand Down

0 comments on commit d9a1bb1

Please sign in to comment.