Index: pkg/analysis_server/test/operation/operation_queue_test.dart |
diff --git a/pkg/analysis_server/test/operation/operation_queue_test.dart b/pkg/analysis_server/test/operation/operation_queue_test.dart |
index 0be1a738121b5ebd8131000c2d01677146a67940..ed7fbcaa117abb07fcd6ef6783ed7183f62316f9 100644 |
--- a/pkg/analysis_server/test/operation/operation_queue_test.dart |
+++ b/pkg/analysis_server/test/operation/operation_queue_test.dart |
@@ -60,6 +60,23 @@ class ServerContextManagerMock extends TypedMock implements ContextManager { |
class ServerOperationQueueTest { |
ServerOperationQueue queue = new ServerOperationQueue(); |
+ void test_add_withMerge() { |
+ var opA = new _MergeableOperationMock(); |
+ var opB = new _MergeableOperationMock(); |
+ var opC = new _MergeableOperationMock(); |
+ when(opA.merge(opC)).thenReturn(true); |
+ when(opA.merge(anyObject)).thenReturn(false); |
+ when(opB.merge(anyObject)).thenReturn(false); |
+ when(opC.merge(anyObject)).thenReturn(false); |
+ queue.add(opA); |
+ queue.add(opB); |
+ queue.add(opC); |
+ expect(queue.take(), same(opA)); |
+ expect(queue.take(), same(opB)); |
+ // no opC, it was merged into opA |
+ expect(queue.isEmpty, isTrue); |
+ } |
+ |
void test_clear() { |
var operationA = mockOperation(ServerOperationPriority.ANALYSIS); |
var operationB = mockOperation(ServerOperationPriority.ANALYSIS_CONTINUE); |
@@ -106,6 +123,20 @@ class ServerOperationQueueTest { |
expect(queue.isEmpty, isTrue); |
} |
+ void test_peek() { |
+ var operationA = mockOperation(ServerOperationPriority.ANALYSIS); |
+ var operationB = mockOperation(ServerOperationPriority.ANALYSIS); |
+ queue.add(operationA); |
+ queue.add(operationB); |
+ expect(queue.peek(), operationA); |
+ expect(queue.peek(), operationA); |
+ expect(queue.peek(), operationA); |
+ } |
+ |
+ void test_peek_empty() { |
+ expect(queue.peek(), isNull); |
+ } |
+ |
void test_reschedule() { |
var prioritySource = new MockSource(); |
var analysisContextA = new AnalysisContextMock(); |
@@ -180,6 +211,27 @@ class ServerOperationQueueTest { |
expect(queue.take(), operationA); |
expect(queue.take(), isNull); |
} |
+ |
+ void test_takeIf() { |
+ var operationA = mockOperation(ServerOperationPriority.ANALYSIS); |
+ var operationB = mockOperation(ServerOperationPriority.ANALYSIS); |
+ queue.add(operationA); |
+ queue.add(operationB); |
+ expect(queue.takeIf((_) => false), isNull); |
+ expect(queue.takeIf((operation) => operation == operationB), operationB); |
+ expect(queue.takeIf((operation) => operation == operationB), isNull); |
+ expect(queue.takeIf((operation) => operation == operationA), operationA); |
+ expect(queue.isEmpty, isTrue); |
+ } |
+} |
+ |
+class _MergeableOperationMock extends TypedMock implements MergeableOperation { |
+ @override |
+ ServerOperationPriority get priority { |
+ return ServerOperationPriority.ANALYSIS_NOTIFICATION; |
+ } |
+ |
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
} |
class _ServerOperationMock extends TypedMock implements ServerOperation { |