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

Side by Side Diff: pkg/analysis_server/test/src/plugin/plugin_manager_test.dart

Issue 2842013003: Add support for watch events and error notifications (Closed)
Patch Set: fix comment Created 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io' as io; 6 import 'dart:io' as io;
7 7
8 import 'package:analysis_server/src/plugin/notification_manager.dart'; 8 import 'package:analysis_server/src/plugin/notification_manager.dart';
9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; 9 import 'package:analysis_server/src/plugin/plugin_manager.dart';
10 import 'package:analyzer/context/context_root.dart'; 10 import 'package:analyzer/context/context_root.dart';
11 import 'package:analyzer/file_system/memory_file_system.dart'; 11 import 'package:analyzer/file_system/memory_file_system.dart';
12 import 'package:analyzer/file_system/physical_file_system.dart'; 12 import 'package:analyzer/file_system/physical_file_system.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart'; 13 import 'package:analyzer/instrumentation/instrumentation.dart';
14 import 'package:analyzer_plugin/channel/channel.dart'; 14 import 'package:analyzer_plugin/channel/channel.dart';
15 import 'package:analyzer_plugin/protocol/protocol.dart'; 15 import 'package:analyzer_plugin/protocol/protocol.dart';
16 import 'package:analyzer_plugin/protocol/protocol_generated.dart' 16 import 'package:analyzer_plugin/protocol/protocol_generated.dart'
17 hide ContextRoot; 17 hide ContextRoot;
18 import 'package:path/path.dart' as path; 18 import 'package:path/path.dart' as path;
19 import 'package:test/test.dart'; 19 import 'package:test/test.dart';
20 import 'package:test_reflective_loader/test_reflective_loader.dart'; 20 import 'package:test_reflective_loader/test_reflective_loader.dart';
21 import 'package:watcher/watcher.dart' as watcher;
21 22
22 main() { 23 main() {
23 defineReflectiveSuite(() { 24 defineReflectiveSuite(() {
24 defineReflectiveTests(PluginInfoTest); 25 defineReflectiveTests(PluginInfoTest);
25 defineReflectiveTests(PluginManagerTest); 26 defineReflectiveTests(PluginManagerTest);
26 defineReflectiveTests(PluginManagerFromDiskTest); 27 defineReflectiveTests(PluginManagerFromDiskTest);
27 defineReflectiveTests(PluginSessionTest); 28 defineReflectiveTests(PluginSessionTest);
28 defineReflectiveTests(PluginSessionFromDiskTest); 29 defineReflectiveTests(PluginSessionFromDiskTest);
29 }); 30 });
30 } 31 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 await withPlugin( 134 await withPlugin(
134 pluginName: 'plugin1', 135 pluginName: 'plugin1',
135 test: (String plugin1Path) async { 136 test: (String plugin1Path) async {
136 await withPlugin( 137 await withPlugin(
137 pluginName: 'plugin2', 138 pluginName: 'plugin2',
138 test: (String plugin2Path) async { 139 test: (String plugin2Path) async {
139 ContextRoot contextRoot = new ContextRoot(pkgPath, []); 140 ContextRoot contextRoot = new ContextRoot(pkgPath, []);
140 await manager.addPluginToContextRoot(contextRoot, plugin1Path); 141 await manager.addPluginToContextRoot(contextRoot, plugin1Path);
141 await manager.addPluginToContextRoot(contextRoot, plugin2Path); 142 await manager.addPluginToContextRoot(contextRoot, plugin2Path);
142 143
143 Map<PluginInfo, Future<Response>> responses = manager.broadcast( 144 Map<PluginInfo, Future<Response>> responses =
144 contextRoot, 145 manager.broadcastRequest(
145 new CompletionGetSuggestionsParams( 146 contextRoot,
146 '/pkg1/lib/pkg1.dart', 100)); 147 new CompletionGetSuggestionsParams(
148 '/pkg1/lib/pkg1.dart', 100));
147 expect(responses, hasLength(2)); 149 expect(responses, hasLength(2));
148 150
149 await manager.stopAll(); 151 await manager.stopAll();
150 }); 152 });
151 }); 153 });
152 pkg1Dir.deleteSync(recursive: true); 154 pkg1Dir.deleteSync(recursive: true);
153 } 155 }
154 156
157 test_broadcastWatchEvent() async {
158 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1');
159 String pkgPath = pkg1Dir.resolveSymbolicLinksSync();
160 await withPlugin(
161 pluginName: 'plugin1',
162 test: (String plugin1Path) async {
163 ContextRoot contextRoot = new ContextRoot(pkgPath, []);
164 await manager.addPluginToContextRoot(contextRoot, plugin1Path);
165 List<PluginInfo> plugins = manager.pluginsForContextRoot(contextRoot);
166 expect(plugins, hasLength(1));
167 watcher.WatchEvent watchEvent = new watcher.WatchEvent(
168 watcher.ChangeType.MODIFY,
169 path.join(plugin1Path, 'lib', 'lib.dart'));
170 List<Future<Response>> responses =
171 await manager.broadcastWatchEvent(watchEvent);
172 expect(responses, hasLength(1));
173 Response response = await responses[0];
174 expect(response, isNotNull);
175 expect(response.error, isNull);
176 await manager.stopAll();
177 });
178 pkg1Dir.deleteSync(recursive: true);
179 }
180
155 test_pluginsForContextRoot_multiple() async { 181 test_pluginsForContextRoot_multiple() async {
156 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1'); 182 io.Directory pkg1Dir = io.Directory.systemTemp.createTempSync('pkg1');
157 String pkgPath = pkg1Dir.resolveSymbolicLinksSync(); 183 String pkgPath = pkg1Dir.resolveSymbolicLinksSync();
158 await withPlugin( 184 await withPlugin(
159 pluginName: 'plugin1', 185 pluginName: 'plugin1',
160 test: (String plugin1Path) async { 186 test: (String plugin1Path) async {
161 await withPlugin( 187 await withPlugin(
162 pluginName: 'plugin2', 188 pluginName: 'plugin2',
163 test: (String plugin2Path) async { 189 test: (String plugin2Path) async {
164 ContextRoot contextRoot = new ContextRoot(pkgPath, []); 190 ContextRoot contextRoot = new ContextRoot(pkgPath, []);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 PluginManager manager; 243 PluginManager manager;
218 244
219 void setUp() { 245 void setUp() {
220 resourceProvider = new MemoryResourceProvider(); 246 resourceProvider = new MemoryResourceProvider();
221 byteStorePath = '/byteStore'; 247 byteStorePath = '/byteStore';
222 notificationManager = new TestNotificationManager(); 248 notificationManager = new TestNotificationManager();
223 manager = new PluginManager(resourceProvider, byteStorePath, 249 manager = new PluginManager(resourceProvider, byteStorePath,
224 notificationManager, InstrumentationService.NULL_SERVICE); 250 notificationManager, InstrumentationService.NULL_SERVICE);
225 } 251 }
226 252
227 void test_broadcast_none() { 253 void test_broadcastRequest_none() {
228 ContextRoot contextRoot = new ContextRoot('/pkg1', []); 254 ContextRoot contextRoot = new ContextRoot('/pkg1', []);
229 Map<PluginInfo, Future<Response>> responses = manager.broadcast(contextRoot, 255 Map<PluginInfo, Future<Response>> responses = manager.broadcastRequest(
256 contextRoot,
230 new CompletionGetSuggestionsParams('/pkg1/lib/pkg1.dart', 100)); 257 new CompletionGetSuggestionsParams('/pkg1/lib/pkg1.dart', 100));
231 expect(responses, hasLength(0)); 258 expect(responses, hasLength(0));
232 } 259 }
233 260
234 void test_creation() { 261 void test_creation() {
235 expect(manager.resourceProvider, resourceProvider); 262 expect(manager.resourceProvider, resourceProvider);
236 expect(manager.byteStorePath, byteStorePath); 263 expect(manager.byteStorePath, byteStorePath);
237 expect(manager.notificationManager, notificationManager); 264 expect(manager.notificationManager, notificationManager);
238 } 265 }
239 266
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 /** 480 /**
454 * The default content of the plugin. This is a minimal plugin that will only 481 * The default content of the plugin. This is a minimal plugin that will only
455 * respond correctly to version checks and to shutdown requests. 482 * respond correctly to version checks and to shutdown requests.
456 */ 483 */
457 String _defaultPluginContent() { 484 String _defaultPluginContent() {
458 return r''' 485 return r'''
459 import 'dart:isolate'; 486 import 'dart:isolate';
460 import 'package:analyzer/file_system/file_system.dart'; 487 import 'package:analyzer/file_system/file_system.dart';
461 import 'package:analyzer/file_system/physical_file_system.dart'; 488 import 'package:analyzer/file_system/physical_file_system.dart';
462 import 'package:analyzer_plugin/plugin/plugin.dart'; 489 import 'package:analyzer_plugin/plugin/plugin.dart';
490 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
463 import 'package:analyzer_plugin/starter.dart'; 491 import 'package:analyzer_plugin/starter.dart';
464 import 'package:pub_semver/pub_semver.dart'; 492 import 'package:pub_semver/pub_semver.dart';
465 493
466 void main(List<String> args, SendPort sendPort) { 494 void main(List<String> args, SendPort sendPort) {
467 MinimalPlugin plugin = new MinimalPlugin(PhysicalResourceProvider.INSTANCE); 495 MinimalPlugin plugin = new MinimalPlugin(PhysicalResourceProvider.INSTANCE);
468 new ServerPluginStarter(plugin).start(sendPort); 496 new ServerPluginStarter(plugin).start(sendPort);
469 } 497 }
470 498
471 class MinimalPlugin extends ServerPlugin { 499 class MinimalPlugin extends ServerPlugin {
472 MinimalPlugin(ResourceProvider provider) : super(provider); 500 MinimalPlugin(ResourceProvider provider) : super(provider);
473 501
474 @override 502 @override
475 List<String> get fileGlobsToAnalyze => <String>[]; 503 List<String> get fileGlobsToAnalyze => <String>['**/*.dart'];
476 504
477 @override 505 @override
478 String get name => 'minimal'; 506 String get name => 'minimal';
479 507
480 @override 508 @override
481 String get version => '0.0.1'; 509 String get version => '0.0.1';
482 510
483 @override 511 @override
512 AnalysisHandleWatchEventsResult handleAnalysisHandleWatchEvents(
513 Map<String, Object> parameters) =>
514 new AnalysisHandleWatchEventsResult();
515
516 @override
484 bool isCompatibleWith(Version serverVersion) => true; 517 bool isCompatibleWith(Version serverVersion) => true;
485 } 518 }
486 '''; 519 ''';
487 } 520 }
488 521
489 /** 522 /**
490 * Return the content to be used for the '.packages' file. 523 * Return the content to be used for the '.packages' file.
491 */ 524 */
492 String _getPackagesFileContent() { 525 String _getPackagesFileContent() {
493 if (_packagesFileContent == null) { 526 if (_packagesFileContent == null) {
494 io.File sdkPackagesFile = new io.File(_sdkPackagesPath()); 527 io.File sdkPackagesFile = new io.File(_sdkPackagesPath());
495 List<String> sdkPackageMap = sdkPackagesFile.readAsLinesSync(); 528 List<String> sdkPackageMap = sdkPackagesFile.readAsLinesSync();
496 _packagesFileContent = 529 _packagesFileContent =
497 _convertPackageMap(path.dirname(sdkPackagesFile.path), sdkPackageMap); 530 _convertPackageMap(path.dirname(sdkPackagesFile.path), sdkPackageMap);
498 } 531 }
499 return _packagesFileContent; 532 return _packagesFileContent;
500 } 533 }
501 534
502 /** 535 /**
503 * Return the path to the '.packages' file in the root of the SDK checkout. 536 * Return the path to the '.packages' file in the root of the SDK checkout.
504 */ 537 */
505 String _sdkPackagesPath() { 538 String _sdkPackagesPath() {
506 String packagesPath = 539 String packagesPath = io.Platform.script.toFilePath();
507 io.Platform.script.toFilePath(windows: io.Platform.isWindows);
508 while (packagesPath.isNotEmpty && 540 while (packagesPath.isNotEmpty &&
509 path.basename(packagesPath) != 'analysis_server') { 541 path.basename(packagesPath) != 'analysis_server') {
510 packagesPath = path.dirname(packagesPath); 542 packagesPath = path.dirname(packagesPath);
511 } 543 }
512 packagesPath = path.dirname(packagesPath); 544 packagesPath = path.dirname(packagesPath);
513 packagesPath = path.dirname(packagesPath); 545 packagesPath = path.dirname(packagesPath);
514 return path.join(packagesPath, '.packages'); 546 return path.join(packagesPath, '.packages');
515 } 547 }
516 } 548 }
517 549
(...skipping 29 matching lines...) Expand all
547 void onNotification(Notification notification), 579 void onNotification(Notification notification),
548 {Function onError, void onDone()}) { 580 {Function onError, void onDone()}) {
549 fail('Unexpected invocation of listen'); 581 fail('Unexpected invocation of listen');
550 } 582 }
551 583
552 @override 584 @override
553 void sendRequest(Request request) { 585 void sendRequest(Request request) {
554 sentRequests.add(request); 586 sentRequests.add(request);
555 } 587 }
556 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698