| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.operation.queue; | 5 library test.operation.queue; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/operation/operation.dart'; | 8 import 'package:analysis_server/src/operation/operation.dart'; |
| 9 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 9 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 10 import 'package:analysis_server/src/operation/operation_queue.dart'; | 10 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:typed_mock/typed_mock.dart'; | 12 import 'package:typed_mock/typed_mock.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 import '../mocks.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; |
| 14 | 16 |
| 15 main() { | 17 main() { |
| 16 groupSep = ' | '; | 18 groupSep = ' | '; |
| 17 | 19 |
| 18 group('ServerOperationQueue', () { | 20 group('ServerOperationQueue', () { |
| 19 ServerOperationQueue queue; | 21 ServerOperationQueue queue; |
| 20 | 22 |
| 21 setUp(() { | 23 setUp(() { |
| 22 queue = new ServerOperationQueue(); | 24 queue = new ServerOperationQueue(); |
| 23 }); | 25 }); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 queue.add(operationB); | 63 queue.add(operationB); |
| 62 queue.add(operationC); | 64 queue.add(operationC); |
| 63 expect(queue.take(), operationC); | 65 expect(queue.take(), operationC); |
| 64 expect(queue.take(), operationB); | 66 expect(queue.take(), operationB); |
| 65 expect(queue.take(), operationA); | 67 expect(queue.take(), operationA); |
| 66 expect(queue.take(), isNull); | 68 expect(queue.take(), isNull); |
| 67 }); | 69 }); |
| 68 | 70 |
| 69 test('continue analysis first', () { | 71 test('continue analysis first', () { |
| 70 var analysisContext = new AnalysisContextMock(); | 72 var analysisContext = new AnalysisContextMock(); |
| 71 var operationA = | 73 var operationA = new PerformAnalysisOperation(analysisContext, false); |
| 72 new PerformAnalysisOperation(analysisContext, false, false); | 74 var operationB = new PerformAnalysisOperation(analysisContext, true); |
| 73 var operationB = | |
| 74 new PerformAnalysisOperation(analysisContext, false, true); | |
| 75 queue.add(operationA); | 75 queue.add(operationA); |
| 76 queue.add(operationB); | 76 queue.add(operationB); |
| 77 expect(queue.take(), operationB); | 77 expect(queue.take(), operationB); |
| 78 expect(queue.take(), operationA); | 78 expect(queue.take(), operationA); |
| 79 expect(queue.take(), isNull); | 79 expect(queue.take(), isNull); |
| 80 }); | 80 }); |
| 81 | 81 |
| 82 test('priority context first', () { | 82 test('priority context first', () { |
| 83 var prioritySource = new MockSource(); |
| 83 var analysisContextA = new AnalysisContextMock(); | 84 var analysisContextA = new AnalysisContextMock(); |
| 84 var analysisContextB = new AnalysisContextMock(); | 85 var analysisContextB = new AnalysisContextMock(); |
| 85 var operationA = | 86 analysisContextB.prioritySources = [prioritySource]; |
| 86 new PerformAnalysisOperation(analysisContextA, false, false); | 87 var operationA = new PerformAnalysisOperation(analysisContextA, false); |
| 87 var operationB = | 88 var operationB = new PerformAnalysisOperation(analysisContextB, false); |
| 88 new PerformAnalysisOperation(analysisContextB, true, false); | |
| 89 queue.add(operationA); | 89 queue.add(operationA); |
| 90 queue.add(operationB); | 90 queue.add(operationB); |
| 91 expect(queue.take(), operationB); | 91 expect(queue.take(), operationB); |
| 92 expect(queue.take(), operationA); | 92 expect(queue.take(), operationA); |
| 93 expect(queue.take(), isNull); | 93 expect(queue.take(), isNull); |
| 94 }); |
| 95 |
| 96 test('reschedule', () { |
| 97 var prioritySource = new MockSource(); |
| 98 var analysisContextA = new AnalysisContextMock(); |
| 99 var analysisContextB = new AnalysisContextMock(); |
| 100 var operationA = new PerformAnalysisOperation(analysisContextA, false); |
| 101 var operationB = new PerformAnalysisOperation(analysisContextB, false); |
| 102 queue.add(operationA); |
| 103 queue.add(operationB); |
| 104 // update priority sources and reschedule |
| 105 analysisContextB.prioritySources = [prioritySource]; |
| 106 queue.reschedule(); |
| 107 // verify order |
| 108 expect(queue.take(), operationB); |
| 109 expect(queue.take(), operationA); |
| 110 expect(queue.take(), isNull); |
| 94 }); | 111 }); |
| 95 }); | 112 }); |
| 96 }); | 113 }); |
| 97 } | 114 } |
| 98 | 115 |
| 99 | 116 |
| 100 /** | 117 /** |
| 101 * Return a [ServerOperation] mock with the given priority. | 118 * Return a [ServerOperation] mock with the given priority. |
| 102 */ | 119 */ |
| 103 ServerOperation mockOperation(ServerOperationPriority priority) { | 120 ServerOperation mockOperation(ServerOperationPriority priority) { |
| 104 ServerOperation operation = new ServerOperationMock(); | 121 ServerOperation operation = new ServerOperationMock(); |
| 105 when(operation.priority).thenReturn(priority); | 122 when(operation.priority).thenReturn(priority); |
| 106 return operation; | 123 return operation; |
| 107 } | 124 } |
| 108 | 125 |
| 109 | 126 |
| 110 class AnalysisContextMock extends TypedMock implements AnalysisContext { | 127 class AnalysisContextMock extends TypedMock implements InternalAnalysisContext { |
| 128 List<Source> prioritySources = <Source>[]; |
| 129 |
| 111 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 130 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 112 } | 131 } |
| 113 | 132 |
| 114 class AnalysisServerMock extends TypedMock implements AnalysisServer { | 133 class AnalysisServerMock extends TypedMock implements AnalysisServer { |
| 115 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 134 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 116 } | 135 } |
| 117 | 136 |
| 118 class ServerContextManagerMock extends TypedMock implements ServerContextManager | 137 class ServerContextManagerMock extends TypedMock implements ServerContextManager |
| 119 { | 138 { |
| 120 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 139 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 121 } | 140 } |
| 122 | 141 |
| 123 class ServerOperationMock extends TypedMock implements ServerOperation { | 142 class ServerOperationMock extends TypedMock implements ServerOperation { |
| 124 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 143 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 125 } | 144 } |
| OLD | NEW |