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

Side by Side Diff: pkg/analysis_server/test/analysis_server_test.dart

Issue 988593002: Don't send notifications for disposed contexts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
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.analysis_server; 5 library test.analysis_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 server.setAnalysisRoots('0', ['/foo'], [], {}); 124 server.setAnalysisRoots('0', ['/foo'], [], {});
125 AnalysisContext context; 125 AnalysisContext context;
126 return pumpEventQueue().then((_) { 126 return pumpEventQueue().then((_) {
127 context = server.getAnalysisContext('/foo/bar.dart'); 127 context = server.getAnalysisContext('/foo/bar.dart');
128 server.setAnalysisRoots('1', [], [], {}); 128 server.setAnalysisRoots('1', [], [], {});
129 }).then((_) => pumpEventQueue()).then((_) { 129 }).then((_) => pumpEventQueue()).then((_) {
130 expect(context.isDisposed, isTrue); 130 expect(context.isDisposed, isTrue);
131 }); 131 });
132 } 132 }
133 133
134 test_getAnalysisContext_nested() {
135 String dir1Path = '/dir1';
136 String dir2Path = dir1Path + '/dir2';
137 String filePath = dir2Path + '/file.dart';
138 Folder dir1 = resourceProvider.newFolder(dir1Path);
139 Folder dir2 = resourceProvider.newFolder(dir2Path);
140 resourceProvider.newFile(filePath, 'library lib;');
141
142 AnalysisContext context1 = AnalysisEngine.instance.createAnalysisContext();
143 AnalysisContext context2 = AnalysisEngine.instance.createAnalysisContext();
144 server.folderMap[dir1] = context1;
145 server.folderMap[dir2] = context2;
146
147 expect(server.getAnalysisContext(filePath), context2);
148 }
149
150 test_getAnalysisContext_simple() {
151 String dirPath = '/dir';
152 String filePath = dirPath + '/file.dart';
153 Folder dir = resourceProvider.newFolder(dirPath);
154 resourceProvider.newFile(filePath, 'library lib;');
155
156 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
157 server.folderMap[dir] = context;
158
159 expect(server.getAnalysisContext(filePath), context);
160 }
161
162 Future test_contextsChangedEvent() { 134 Future test_contextsChangedEvent() {
163 resourceProvider.newFolder('/foo'); 135 resourceProvider.newFolder('/foo');
164 136
165 bool wasAdded = false; 137 bool wasAdded = false;
166 bool wasChanged = false; 138 bool wasChanged = false;
167 bool wasRemoved = false; 139 bool wasRemoved = false;
168 server.onContextsChanged.listen((ContextsChangedEvent event) { 140 server.onContextsChanged.listen((ContextsChangedEvent event) {
169 wasAdded = event.added.length == 1; 141 wasAdded = event.added.length == 1;
170 if (wasAdded) { 142 if (wasAdded) {
171 expect(event.added[0], isNotNull); 143 expect(event.added[0], isNotNull);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 182
211 Future test_echo() { 183 Future test_echo() {
212 server.handlers = [new EchoHandler()]; 184 server.handlers = [new EchoHandler()];
213 var request = new Request('my22', 'echo'); 185 var request = new Request('my22', 'echo');
214 return channel.sendRequest(request).then((Response response) { 186 return channel.sendRequest(request).then((Response response) {
215 expect(response.id, equals('my22')); 187 expect(response.id, equals('my22'));
216 expect(response.error, isNull); 188 expect(response.error, isNull);
217 }); 189 });
218 } 190 }
219 191
192 test_getAnalysisContext_nested() {
193 String dir1Path = '/dir1';
194 String dir2Path = dir1Path + '/dir2';
195 String filePath = dir2Path + '/file.dart';
196 Folder dir1 = resourceProvider.newFolder(dir1Path);
197 Folder dir2 = resourceProvider.newFolder(dir2Path);
198 resourceProvider.newFile(filePath, 'library lib;');
199
200 AnalysisContext context1 = AnalysisEngine.instance.createAnalysisContext();
201 AnalysisContext context2 = AnalysisEngine.instance.createAnalysisContext();
202 server.folderMap[dir1] = context1;
203 server.folderMap[dir2] = context2;
204
205 expect(server.getAnalysisContext(filePath), context2);
206 }
207
208 test_getAnalysisContext_simple() {
209 String dirPath = '/dir';
210 String filePath = dirPath + '/file.dart';
211 Folder dir = resourceProvider.newFolder(dirPath);
212 resourceProvider.newFile(filePath, 'library lib;');
213
214 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
215 server.folderMap[dir] = context;
216
217 expect(server.getAnalysisContext(filePath), context);
218 }
219
220 Future test_getAnalysisContextForSource() { 220 Future test_getAnalysisContextForSource() {
221 // Subscribe to STATUS so we'll know when analysis is done. 221 // Subscribe to STATUS so we'll know when analysis is done.
222 server.serverServices = [ServerService.STATUS].toSet(); 222 server.serverServices = [ServerService.STATUS].toSet();
223 // Analyze project foo containing foo.dart and project bar containing 223 // Analyze project foo containing foo.dart and project bar containing
224 // bar.dart. 224 // bar.dart.
225 resourceProvider.newFolder('/foo'); 225 resourceProvider.newFolder('/foo');
226 resourceProvider.newFolder('/bar'); 226 resourceProvider.newFolder('/bar');
227 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;'); 227 File foo = resourceProvider.newFile('/foo/foo.dart', 'library lib;');
228 Source fooSource = foo.createSource(); 228 Source fooSource = foo.createSource();
229 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;'); 229 File bar = resourceProvider.newFile('/bar/bar.dart', 'library lib;');
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 break; 286 break;
287 default: 287 default:
288 if (!notificationTypesReceived.add(notificationType)) { 288 if (!notificationTypesReceived.add(notificationType)) {
289 fail('Notification type $notificationType received more than once'); 289 fail('Notification type $notificationType received more than once');
290 } 290 }
291 break; 291 break;
292 } 292 }
293 } 293 }
294 } 294 }
295 295
296 test_operationsRemovedOnContextDisposal() async {
297 resourceProvider.newFolder('/foo');
298 resourceProvider.newFile('/foo/baz.dart', 'library lib;');
299 resourceProvider.newFolder('/bar');
300 resourceProvider.newFile('/bar/baz.dart', 'library lib;');
301 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {});
302 await pumpEventQueue();
303 AnalysisContext contextFoo = server.getAnalysisContext('/foo/baz.dart');
304 AnalysisContext contextBar = server.getAnalysisContext('/bar/baz.dart');
305 _MockServerOperation operationFoo = new _MockServerOperation(contextFoo);
306 _MockServerOperation operationBar = new _MockServerOperation(contextBar);
307 server.scheduleOperation(operationFoo);
308 server.scheduleOperation(operationBar);
309 server.setAnalysisRoots('1', ['/foo'], [], {});
310 await pumpEventQueue();
311 expect(operationFoo.isComplete, isTrue);
312 expect(operationBar.isComplete, isFalse);
313 }
314
296 Future test_prioritySourcesChangedEvent() { 315 Future test_prioritySourcesChangedEvent() {
297 resourceProvider.newFolder('/foo'); 316 resourceProvider.newFolder('/foo');
298 317
299 int eventCount = 0; 318 int eventCount = 0;
300 Source firstSource = null; 319 Source firstSource = null;
301 server.onPriorityChange.listen((PriorityChangeEvent event) { 320 server.onPriorityChange.listen((PriorityChangeEvent event) {
302 ++eventCount; 321 ++eventCount;
303 firstSource = event.firstSource; 322 firstSource = event.firstSource;
304 }); 323 });
305 324
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 417
399 class EchoHandler implements RequestHandler { 418 class EchoHandler implements RequestHandler {
400 @override 419 @override
401 Response handleRequest(Request request) { 420 Response handleRequest(Request request) {
402 if (request.method == 'echo') { 421 if (request.method == 'echo') {
403 return new Response(request.id, result: {'echo': true}); 422 return new Response(request.id, result: {'echo': true});
404 } 423 }
405 return null; 424 return null;
406 } 425 }
407 } 426 }
427
428 /**
429 * A [ServerOperation] that does nothing but keep track of whether or not it
430 * has been performed.
431 */
432 class _MockServerOperation implements ServerOperation {
433 final AnalysisContext context;
434 bool isComplete = false;
435
436 _MockServerOperation(this.context);
437
438 @override
439 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS;
440
441 @override
442 void perform(AnalysisServer server) {
443 isComplete = true;
444 }
445 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698