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

Side by Side Diff: pkg/analyzer/test/src/task/dart_work_manager_test.dart

Issue 1132893003: Add DartWorkManager to manage Dart-specific results computation scheduling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library test.src.task.dart_work_manager_test;
6
7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/engine.dart'
9 show CacheState, InternalAnalysisContext;
10 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/task/dart.dart';
13 import 'package:analyzer/src/task/dart_work_manager.dart';
14 import 'package:analyzer/task/dart.dart';
15 import 'package:typed_mock/typed_mock.dart';
16 import 'package:unittest/unittest.dart';
17
18 import '../../generated/test_support.dart';
19 import '../../reflective_tests.dart';
20
21 main() {
22 groupSep = ' | ';
23 runReflectiveTests(DartWorkManagerTest);
24 }
25
26 @reflectiveTest
27 class DartWorkManagerTest {
28 AnalysisCache cache;
29 InternalAnalysisContext context = new _InternalAnalysisContextMock();
30 DartWorkManager manager;
31
32 CaughtException caughtException = new CaughtException(null, null);
33
34 Source source1 = new TestSource('1.dart');
35 Source source2 = new TestSource('2.dart');
36 Source source3 = new TestSource('3.dart');
37 Source source4 = new TestSource('4.dart');
38 CacheEntry entry1;
39 CacheEntry entry2;
40 CacheEntry entry3;
41 CacheEntry entry4;
42
43 void expect_explicitSources(List<Source> sources) {
44 expect(manager.explicitSources, unorderedEquals(sources));
45 }
46
47 void expect_librarySourceQueue(List<Source> sources) {
48 expect(manager.librarySourceQueue, orderedEquals(sources));
49 }
50
51 void expect_librarySources(List<Source> sources) {
52 expect(manager.librarySources, unorderedEquals(sources));
53 }
54
55 void expect_partSources(List<Source> sources) {
56 expect(manager.partSources, unorderedEquals(sources));
57 }
58
59 void expect_unknownSourceQueue(List<Source> sources) {
60 expect(manager.unknownSourceQueue, orderedEquals(sources));
61 }
62
63 void setUp() {
64 cache = new AnalysisCache([new UniversalCachePartition(context)]);
65 manager = new DartWorkManager(context);
66 entry1 = new CacheEntry(source1);
67 entry2 = new CacheEntry(source2);
68 entry3 = new CacheEntry(source3);
69 entry4 = new CacheEntry(source4);
70 cache.put(entry1);
71 cache.put(entry2);
72 cache.put(entry3);
73 cache.put(entry4);
74 when(context.getCacheEntry(source1)).thenReturn(entry1);
75 when(context.getCacheEntry(source2)).thenReturn(entry2);
76 when(context.getCacheEntry(source3)).thenReturn(entry3);
77 when(context.getCacheEntry(source4)).thenReturn(entry4);
78 }
79
80 void test_applyChange_add() {
81 // add source1
82 manager.applyChange([source1], [], []);
83 expect_explicitSources([source1]);
84 expect_librarySources([]);
85 expect_partSources([]);
86 expect_unknownSourceQueue([source1]);
87 expect_librarySourceQueue([]);
88 // add source2
89 manager.applyChange([source2], [], []);
90 expect_explicitSources([source1, source2]);
91 expect_librarySources([]);
92 expect_partSources([]);
93 expect_librarySourceQueue([]);
94 expect_unknownSourceQueue([source1, source2]);
95 }
96
97 void test_applyChange_add_duplicate() {
98 // add source1
99 manager.applyChange([source1], [], []);
100 expect_explicitSources([source1]);
101 expect_librarySources([]);
102 expect_partSources([]);
103 expect_unknownSourceQueue([source1]);
104 expect_librarySourceQueue([]);
105 // add source2
106 manager.applyChange([source1], [], []);
107 expect_explicitSources([source1]);
108 expect_librarySources([]);
109 expect_partSources([]);
110 expect_librarySourceQueue([]);
111 expect_unknownSourceQueue([source1]);
112 }
113
114 void test_applyChange_addRemove() {
115 manager.applyChange([source1, source2], [], [source2, source3]);
116 expect_explicitSources([source1]);
117 expect_librarySources([]);
118 expect_partSources([]);
119 expect_unknownSourceQueue([source1]);
120 expect_librarySourceQueue([]);
121 }
122
123 void test_applyChange_change() {
124 manager.explicitSources.addAll([source1, source2, source3]);
125 manager.librarySources.addAll([source1, source3]);
126 manager.partSources.addAll([source2]);
127 manager.librarySourceQueue.addAll([source1, source3]);
128 manager.unknownSourceQueue.addAll([source4]);
129 // change source1
130 manager.applyChange([], [source1], []);
131 expect_explicitSources([source1, source2, source3]);
132 expect_librarySources([source3]);
133 expect_partSources([source2]);
134 expect_librarySourceQueue([source3]);
135 expect_unknownSourceQueue([source4, source1]);
136 }
137
138 void test_applyChange_remove() {
139 manager.explicitSources.addAll([source1, source2, source3]);
140 manager.librarySources.addAll([source1, source3]);
141 manager.partSources.addAll([source2]);
142 manager.librarySourceQueue.addAll([source1, source3]);
143 manager.unknownSourceQueue.addAll([source4]);
144 // remove source1
145 manager.applyChange([], [], [source1]);
146 expect_explicitSources([source2, source3]);
147 expect_librarySources([source3]);
148 expect_partSources([source2]);
149 expect_librarySourceQueue([source3]);
150 expect_unknownSourceQueue([source4]);
151 // remove source3
152 manager.applyChange([], [], [source3]);
153 expect_explicitSources([source2]);
154 expect_librarySources([]);
155 expect_partSources([source2]);
156 expect_librarySourceQueue([]);
157 expect_unknownSourceQueue([source4]);
158 // remove source4
159 manager.applyChange([], [], [source4]);
160 expect_explicitSources([source2]);
161 expect_librarySources([]);
162 expect_partSources([source2]);
163 expect_librarySourceQueue([]);
164 expect_unknownSourceQueue([]);
165 }
166
167 void test_getNextResult_hasLibraries_firstIsError() {
168 entry1.setErrorState(caughtException, [LIBRARY_ERRORS_READY]);
169 manager.librarySourceQueue.addAll([source1, source2]);
170 TargetedResult request = manager.getNextResult();
171 expect(request.target, source2);
172 expect(request.result, LIBRARY_ERRORS_READY);
173 // source1 is out, source2 is waiting
174 expect_librarySourceQueue([source2]);
175 }
176
177 void test_getNextResult_hasLibraries_firstIsInvalid() {
178 entry1.setState(LIBRARY_ERRORS_READY, CacheState.INVALID);
179 manager.librarySourceQueue.addAll([source1, source2]);
180 TargetedResult request = manager.getNextResult();
181 expect(request.target, source1);
182 expect(request.result, LIBRARY_ERRORS_READY);
183 // no changes until computed
184 expect_librarySourceQueue([source1, source2]);
185 }
186
187 void test_getNextResult_hasLibraries_firstIsValid() {
188 entry1.setValue(LIBRARY_ERRORS_READY, true, []);
189 manager.librarySourceQueue.addAll([source1, source2]);
190 TargetedResult request = manager.getNextResult();
191 expect(request.target, source2);
192 expect(request.result, LIBRARY_ERRORS_READY);
193 // source1 is out, source2 is waiting
194 expect_librarySourceQueue([source2]);
195 }
196
197 void test_getNextResult_hasLibraries_nothingToDo() {
198 manager.librarySources.addAll([source1]);
199 manager.partSources.addAll([source2]);
200 TargetedResult request = manager.getNextResult();
201 expect(request, isNull);
202 }
203
204 void test_getNextResult_hasUnknown_firstIsError() {
205 entry1.setErrorState(caughtException, [SOURCE_KIND]);
206 manager.unknownSourceQueue.addAll([source1, source2]);
207 TargetedResult request = manager.getNextResult();
208 expect(request.target, source2);
209 expect(request.result, SOURCE_KIND);
210 // source1 is out, source2 is waiting
211 expect_librarySourceQueue([]);
212 expect_unknownSourceQueue([source2]);
213 }
214
215 void test_getNextResult_hasUnknown_firstIsInvalid() {
216 manager.unknownSourceQueue.addAll([source1, source2]);
217 TargetedResult request = manager.getNextResult();
218 expect(request.target, source1);
219 expect(request.result, SOURCE_KIND);
220 // no changes until computed
221 expect_librarySourceQueue([]);
222 expect_unknownSourceQueue([source1, source2]);
223 }
224
225 void test_getNextResult_hasUnknown_firstIsValid() {
226 entry1.setValue(SOURCE_KIND, SourceKind.LIBRARY, []);
227 manager.unknownSourceQueue.addAll([source1, source2]);
228 TargetedResult request = manager.getNextResult();
229 expect(request.target, source2);
230 expect(request.result, SOURCE_KIND);
231 // source1 is out, source2 is waiting
232 expect_librarySourceQueue([]);
233 expect_unknownSourceQueue([source2]);
234 }
235
236 void test_resultsComputed_isLibrary() {
237 manager.unknownSourceQueue.addAll([source1, source2, source3]);
238 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.LIBRARY});
239 expect_librarySources([source2]);
240 expect_partSources([]);
241 expect_librarySourceQueue([source2]);
242 expect_unknownSourceQueue([source1, source3]);
243 }
244
245 void test_resultsComputed_isPart() {
246 manager.unknownSourceQueue.addAll([source1, source2, source3]);
247 manager.resultsComputed(source2, {SOURCE_KIND: SourceKind.PART});
248 expect_librarySources([]);
249 expect_partSources([source2]);
250 expect_librarySourceQueue([]);
251 expect_unknownSourceQueue([source1, source3]);
252 }
253
254 void test_resultsComputed_noSourceKind() {
255 manager.unknownSourceQueue.addAll([source1, source2]);
256 manager.resultsComputed(source1, {});
257 expect_librarySources([]);
258 expect_partSources([]);
259 expect_librarySourceQueue([]);
260 expect_unknownSourceQueue([source1, source2]);
261 }
262
263 void test_resultsComputed_notDart() {
264 manager.unknownSourceQueue.addAll([source1, source2]);
265 manager.resultsComputed(new TestSource('test.html'), {});
266 expect_librarySources([]);
267 expect_partSources([]);
268 expect_librarySourceQueue([]);
269 expect_unknownSourceQueue([source1, source2]);
270 }
271 }
272
273 class _InternalAnalysisContextMock extends TypedMock
274 implements InternalAnalysisContext {
275 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698