Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: pkg/analysis_server/test/operation/operation_queue_test.dart

Issue 1327173002: Make NavigationOperation a MergeableOperation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_queue.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_queue.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698