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

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

Issue 846723002: Make domains plugable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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.socket.server; 5 library test.socket.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';
11 import 'package:analysis_server/src/plugin/server_plugin.dart';
11 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_server/src/socket_server.dart'; 13 import 'package:analysis_server/src/socket_server.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
14 import 'package:analyzer/src/generated/sdk_io.dart'; 15 import 'package:analyzer/src/generated/sdk_io.dart';
15 import 'package:unittest/unittest.dart'; 16 import 'package:unittest/unittest.dart';
16 17
17 import 'mocks.dart'; 18 import 'mocks.dart';
19 import 'package:analysis_server/src/plugin/plugin_impl.dart';
18 20
19 main() { 21 main() {
20 group('SocketServer', () { 22 group('SocketServer', () {
21 test( 23 test(
22 'createAnalysisServer_successful', 24 'createAnalysisServer_successful',
23 SocketServerTest.createAnalysisServer_successful); 25 SocketServerTest.createAnalysisServer_successful);
24 test( 26 test(
25 'createAnalysisServer_alreadyStarted', 27 'createAnalysisServer_alreadyStarted',
26 SocketServerTest.createAnalysisServer_alreadyStarted); 28 SocketServerTest.createAnalysisServer_alreadyStarted);
27 test('requestHandler_exception', SocketServerTest.requestHandler_exception); 29 test('requestHandler_exception', SocketServerTest.requestHandler_exception);
28 test( 30 test(
29 'requestHandler_futureException', 31 'requestHandler_futureException',
30 SocketServerTest.requestHandler_futureException); 32 SocketServerTest.requestHandler_futureException);
31 }); 33 });
32 } 34 }
33 35
34 class SocketServerTest { 36 class SocketServerTest {
35 static void createAnalysisServer_alreadyStarted() { 37 static void createAnalysisServer_alreadyStarted() {
36 SocketServer server = new SocketServer( 38 SocketServer server = _createSocketServer();
37 new AnalysisServerOptions(),
38 DirectoryBasedDartSdk.defaultSdk,
39 InstrumentationService.NULL_SERVICE);
40 MockServerChannel channel1 = new MockServerChannel(); 39 MockServerChannel channel1 = new MockServerChannel();
41 MockServerChannel channel2 = new MockServerChannel(); 40 MockServerChannel channel2 = new MockServerChannel();
42 server.createAnalysisServer(channel1); 41 server.createAnalysisServer(channel1);
43 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED); 42 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED);
44 server.createAnalysisServer(channel2); 43 server.createAnalysisServer(channel2);
45 channel1.expectMsgCount(notificationCount: 1); 44 channel1.expectMsgCount(notificationCount: 1);
46 channel2.expectMsgCount(responseCount: 1); 45 channel2.expectMsgCount(responseCount: 1);
47 expect(channel2.responsesReceived[0].id, equals('')); 46 expect(channel2.responsesReceived[0].id, equals(''));
48 expect(channel2.responsesReceived[0].error, isNotNull); 47 expect(channel2.responsesReceived[0].error, isNotNull);
49 expect( 48 expect(
50 channel2.responsesReceived[0].error.code, 49 channel2.responsesReceived[0].error.code,
51 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); 50 equals(RequestErrorCode.SERVER_ALREADY_STARTED));
52 channel2.sendRequest( 51 channel2.sendRequest(
53 new ServerShutdownParams().toRequest('0')).then((Response response) { 52 new ServerShutdownParams().toRequest('0')).then((Response response) {
54 expect(response.id, equals('0')); 53 expect(response.id, equals('0'));
55 expect(response.error, isNotNull); 54 expect(response.error, isNotNull);
56 expect( 55 expect(
57 response.error.code, 56 response.error.code,
58 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); 57 equals(RequestErrorCode.SERVER_ALREADY_STARTED));
59 channel2.expectMsgCount(responseCount: 2); 58 channel2.expectMsgCount(responseCount: 2);
60 }); 59 });
61 } 60 }
62 61
63 static Future createAnalysisServer_successful() { 62 static Future createAnalysisServer_successful() {
64 SocketServer server = new SocketServer( 63 SocketServer server = _createSocketServer();
65 new AnalysisServerOptions(),
66 DirectoryBasedDartSdk.defaultSdk,
67 InstrumentationService.NULL_SERVICE);
68 MockServerChannel channel = new MockServerChannel(); 64 MockServerChannel channel = new MockServerChannel();
69 server.createAnalysisServer(channel); 65 server.createAnalysisServer(channel);
70 channel.expectMsgCount(notificationCount: 1); 66 channel.expectMsgCount(notificationCount: 1);
71 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); 67 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED);
72 return channel.sendRequest( 68 return channel.sendRequest(
73 new ServerShutdownParams().toRequest('0')).then((Response response) { 69 new ServerShutdownParams().toRequest('0')).then((Response response) {
74 expect(response.id, equals('0')); 70 expect(response.id, equals('0'));
75 expect(response.error, isNull); 71 expect(response.error, isNull);
76 channel.expectMsgCount(responseCount: 1, notificationCount: 1); 72 channel.expectMsgCount(responseCount: 1, notificationCount: 1);
77 }); 73 });
78 } 74 }
79 75
80 static Future requestHandler_exception() { 76 static Future requestHandler_exception() {
81 SocketServer server = new SocketServer( 77 SocketServer server = _createSocketServer();
82 new AnalysisServerOptions(),
83 DirectoryBasedDartSdk.defaultSdk,
84 InstrumentationService.NULL_SERVICE);
85 MockServerChannel channel = new MockServerChannel(); 78 MockServerChannel channel = new MockServerChannel();
86 server.createAnalysisServer(channel); 79 server.createAnalysisServer(channel);
87 channel.expectMsgCount(notificationCount: 1); 80 channel.expectMsgCount(notificationCount: 1);
88 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); 81 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED);
89 _MockRequestHandler handler = new _MockRequestHandler(false); 82 _MockRequestHandler handler = new _MockRequestHandler(false);
90 server.analysisServer.handlers = [handler]; 83 server.analysisServer.handlers = [handler];
91 var request = new ServerGetVersionParams().toRequest('0'); 84 var request = new ServerGetVersionParams().toRequest('0');
92 return channel.sendRequest(request).then((Response response) { 85 return channel.sendRequest(request).then((Response response) {
93 expect(response.id, equals('0')); 86 expect(response.id, equals('0'));
94 expect(response.error, isNotNull); 87 expect(response.error, isNotNull);
95 expect(response.error.code, equals(RequestErrorCode.SERVER_ERROR)); 88 expect(response.error.code, equals(RequestErrorCode.SERVER_ERROR));
96 expect(response.error.message, equals('mock request exception')); 89 expect(response.error.message, equals('mock request exception'));
97 expect(response.error.stackTrace, isNotNull); 90 expect(response.error.stackTrace, isNotNull);
98 expect(response.error.stackTrace, isNotEmpty); 91 expect(response.error.stackTrace, isNotEmpty);
99 channel.expectMsgCount(responseCount: 1, notificationCount: 1); 92 channel.expectMsgCount(responseCount: 1, notificationCount: 1);
100 }); 93 });
101 } 94 }
102 95
103 static Future requestHandler_futureException() { 96 static Future requestHandler_futureException() {
104 SocketServer server = new SocketServer( 97 SocketServer server = _createSocketServer();
105 new AnalysisServerOptions(),
106 DirectoryBasedDartSdk.defaultSdk,
107 InstrumentationService.NULL_SERVICE);
108 MockServerChannel channel = new MockServerChannel(); 98 MockServerChannel channel = new MockServerChannel();
109 server.createAnalysisServer(channel); 99 server.createAnalysisServer(channel);
110 _MockRequestHandler handler = new _MockRequestHandler(true); 100 _MockRequestHandler handler = new _MockRequestHandler(true);
111 server.analysisServer.handlers = [handler]; 101 server.analysisServer.handlers = [handler];
112 var request = new ServerGetVersionParams().toRequest('0'); 102 var request = new ServerGetVersionParams().toRequest('0');
113 return channel.sendRequest(request).then((Response response) { 103 return channel.sendRequest(request).then((Response response) {
114 expect(response.id, equals('0')); 104 expect(response.id, equals('0'));
115 expect(response.error, isNull); 105 expect(response.error, isNull);
116 channel.expectMsgCount(responseCount: 1, notificationCount: 2); 106 channel.expectMsgCount(responseCount: 1, notificationCount: 2);
117 expect(channel.notificationsReceived[1].event, SERVER_ERROR); 107 expect(channel.notificationsReceived[1].event, SERVER_ERROR);
118 }); 108 });
119 } 109 }
110
111 static SocketServer _createSocketServer() {
112 ServerPlugin serverPlugin = new ServerPlugin();
113 ExtensionManager manager = new ExtensionManager();
114 manager.processPlugins([serverPlugin]);
115 return new SocketServer(
116 new AnalysisServerOptions(),
117 DirectoryBasedDartSdk.defaultSdk,
118 InstrumentationService.NULL_SERVICE,
119 serverPlugin);
120 }
120 } 121 }
121 122
122 class _MockRequestHandler implements RequestHandler { 123 class _MockRequestHandler implements RequestHandler {
123 final bool futureException; 124 final bool futureException;
124 125
125 _MockRequestHandler(this.futureException); 126 _MockRequestHandler(this.futureException);
126 127
127 @override 128 @override
128 Response handleRequest(Request request) { 129 Response handleRequest(Request request) {
129 if (futureException) { 130 if (futureException) {
130 new Future(throwException); 131 new Future(throwException);
131 return new Response(request.id); 132 return new Response(request.id);
132 } 133 }
133 throw 'mock request exception'; 134 throw 'mock request exception';
134 } 135 }
135 136
136 void throwException() { 137 void throwException() {
137 throw 'mock future exception'; 138 throw 'mock future exception';
138 } 139 }
139 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698