OLD | NEW |
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'; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 fail('Expected a StateError'); | 83 fail('Expected a StateError'); |
84 } on StateError { | 84 } on StateError { |
85 // Expected. | 85 // Expected. |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 test_stop_notRunning() { | 89 test_stop_notRunning() { |
90 expect(() => plugin.stop(), throwsA(new isInstanceOf<StateError>())); | 90 expect(() => plugin.stop(), throwsA(new isInstanceOf<StateError>())); |
91 } | 91 } |
92 | 92 |
93 test_stop_running() { | 93 test_stop_running() async { |
94 PluginSession session = new PluginSession(plugin); | 94 PluginSession session = new PluginSession(plugin); |
95 TestServerCommunicationChannel channel = | 95 TestServerCommunicationChannel channel = |
96 new TestServerCommunicationChannel(session); | 96 new TestServerCommunicationChannel(session); |
97 plugin.currentSession = session; | 97 plugin.currentSession = session; |
98 plugin.stop(); | 98 await plugin.stop(); |
99 expect(plugin.currentSession, isNull); | 99 expect(plugin.currentSession, isNull); |
100 expect(channel.sentRequests, hasLength(1)); | 100 expect(channel.sentRequests, hasLength(1)); |
101 expect(channel.sentRequests[0].method, 'plugin.shutdown'); | 101 expect(channel.sentRequests[0].method, 'plugin.shutdown'); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 @reflectiveTest | 105 @reflectiveTest |
106 class DiscoveredPluginInfoTest { | 106 class DiscoveredPluginInfoTest { |
107 MemoryResourceProvider resourceProvider; | 107 MemoryResourceProvider resourceProvider; |
108 TestNotificationManager notificationManager; | 108 TestNotificationManager notificationManager; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 fail('Expected a StateError'); | 159 fail('Expected a StateError'); |
160 } on StateError { | 160 } on StateError { |
161 // Expected. | 161 // Expected. |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 test_stop_notRunning() { | 165 test_stop_notRunning() { |
166 expect(() => plugin.stop(), throwsA(new isInstanceOf<StateError>())); | 166 expect(() => plugin.stop(), throwsA(new isInstanceOf<StateError>())); |
167 } | 167 } |
168 | 168 |
169 test_stop_running() { | 169 test_stop_running() async { |
170 PluginSession session = new PluginSession(plugin); | 170 PluginSession session = new PluginSession(plugin); |
171 TestServerCommunicationChannel channel = | 171 TestServerCommunicationChannel channel = |
172 new TestServerCommunicationChannel(session); | 172 new TestServerCommunicationChannel(session); |
173 plugin.currentSession = session; | 173 plugin.currentSession = session; |
174 plugin.stop(); | 174 await plugin.stop(); |
175 expect(plugin.currentSession, isNull); | 175 expect(plugin.currentSession, isNull); |
176 expect(channel.sentRequests, hasLength(1)); | 176 expect(channel.sentRequests, hasLength(1)); |
177 expect(channel.sentRequests[0].method, 'plugin.shutdown'); | 177 expect(channel.sentRequests[0].method, 'plugin.shutdown'); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 @reflectiveTest | 181 @reflectiveTest |
182 class PluginManagerFromDiskTest extends PluginTestSupport { | 182 class PluginManagerFromDiskTest extends PluginTestSupport { |
183 String byteStorePath = '/byteStore'; | 183 String byteStorePath = '/byteStore'; |
184 PluginManager manager; | 184 PluginManager manager; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 fail('Expected a StateError to be thrown'); | 484 fail('Expected a StateError to be thrown'); |
485 } on StateError { | 485 } on StateError { |
486 // Expected behavior | 486 // Expected behavior |
487 } | 487 } |
488 } | 488 } |
489 | 489 |
490 test_stop_notRunning() { | 490 test_stop_notRunning() { |
491 expect(() => session.stop(), throwsA(new isInstanceOf<StateError>())); | 491 expect(() => session.stop(), throwsA(new isInstanceOf<StateError>())); |
492 } | 492 } |
493 | 493 |
494 void test_stop_running() { | 494 test_stop_running() async { |
495 TestServerCommunicationChannel channel = | 495 TestServerCommunicationChannel channel = |
496 new TestServerCommunicationChannel(session); | 496 new TestServerCommunicationChannel(session); |
497 session.stop(); | 497 await session.stop(); |
498 expect(channel.sentRequests, hasLength(1)); | 498 expect(channel.sentRequests, hasLength(1)); |
499 expect(channel.sentRequests[0].method, 'plugin.shutdown'); | 499 expect(channel.sentRequests[0].method, 'plugin.shutdown'); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 /** | 503 /** |
504 * A class designed to be used as a superclass for test classes that define | 504 * A class designed to be used as a superclass for test classes that define |
505 * tests that require plugins to be created on disk. | 505 * tests that require plugins to be created on disk. |
506 */ | 506 */ |
507 abstract class PluginTestSupport { | 507 abstract class PluginTestSupport { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 notifications.add(notification); | 664 notifications.add(notification); |
665 } | 665 } |
666 | 666 |
667 @override | 667 @override |
668 noSuchMethod(Invocation invocation) { | 668 noSuchMethod(Invocation invocation) { |
669 fail('Unexpected invocation of ${invocation.memberName}'); | 669 fail('Unexpected invocation of ${invocation.memberName}'); |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 class TestServerCommunicationChannel implements ServerCommunicationChannel { | 673 class TestServerCommunicationChannel implements ServerCommunicationChannel { |
| 674 final PluginSession session; |
674 int closeCount = 0; | 675 int closeCount = 0; |
675 List<Request> sentRequests = <Request>[]; | 676 List<Request> sentRequests = <Request>[]; |
676 | 677 |
677 TestServerCommunicationChannel(PluginSession session) { | 678 TestServerCommunicationChannel(this.session) { |
678 session.channel = this; | 679 session.channel = this; |
679 } | 680 } |
680 | 681 |
681 @override | 682 @override |
682 void close() { | 683 void close() { |
683 closeCount++; | 684 closeCount++; |
684 } | 685 } |
685 | 686 |
| 687 void kill() { |
| 688 fail('Unexpected invocation of kill'); |
| 689 } |
| 690 |
686 @override | 691 @override |
687 void listen(void onResponse(Response response), | 692 void listen(void onResponse(Response response), |
688 void onNotification(Notification notification), | 693 void onNotification(Notification notification), |
689 {Function onError, void onDone()}) { | 694 {Function onError, void onDone()}) { |
690 fail('Unexpected invocation of listen'); | 695 fail('Unexpected invocation of listen'); |
691 } | 696 } |
692 | 697 |
693 @override | 698 @override |
694 void sendRequest(Request request) { | 699 void sendRequest(Request request) { |
695 sentRequests.add(request); | 700 sentRequests.add(request); |
| 701 if (request.method == 'plugin.shutdown') { |
| 702 session.handleOnDone(); |
| 703 } |
696 } | 704 } |
697 } | 705 } |
OLD | NEW |