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

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

Issue 787763004: Hooks for instrumentation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
« no previous file with comments | « pkg/analysis_server/test/domain_server_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_server/src/socket_server.dart'; 12 import 'package:analysis_server/src/socket_server.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart';
13 import 'package:analyzer/src/generated/sdk_io.dart'; 14 import 'package:analyzer/src/generated/sdk_io.dart';
14 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
15 16
16 import 'mocks.dart'; 17 import 'mocks.dart';
17 18
18 main() { 19 main() {
19 group('SocketServer', () { 20 group('SocketServer', () {
20 test( 21 test(
21 'createAnalysisServer_successful', 22 'createAnalysisServer_successful',
22 SocketServerTest.createAnalysisServer_successful); 23 SocketServerTest.createAnalysisServer_successful);
23 test( 24 test(
24 'createAnalysisServer_alreadyStarted', 25 'createAnalysisServer_alreadyStarted',
25 SocketServerTest.createAnalysisServer_alreadyStarted); 26 SocketServerTest.createAnalysisServer_alreadyStarted);
26 test('requestHandler_exception', SocketServerTest.requestHandler_exception); 27 test('requestHandler_exception', SocketServerTest.requestHandler_exception);
27 test( 28 test(
28 'requestHandler_futureException', 29 'requestHandler_futureException',
29 SocketServerTest.requestHandler_futureException); 30 SocketServerTest.requestHandler_futureException);
30 }); 31 });
31 } 32 }
32 33
33 class SocketServerTest { 34 class SocketServerTest {
34 static void createAnalysisServer_alreadyStarted() { 35 static void createAnalysisServer_alreadyStarted() {
35 SocketServer server = new SocketServer( 36 SocketServer server = new SocketServer(
36 new AnalysisServerOptions(), 37 new AnalysisServerOptions(),
37 DirectoryBasedDartSdk.defaultSdk); 38 DirectoryBasedDartSdk.defaultSdk,
39 new NullInstrumentationServer());
38 MockServerChannel channel1 = new MockServerChannel(); 40 MockServerChannel channel1 = new MockServerChannel();
39 MockServerChannel channel2 = new MockServerChannel(); 41 MockServerChannel channel2 = new MockServerChannel();
40 server.createAnalysisServer(channel1); 42 server.createAnalysisServer(channel1);
41 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED); 43 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED);
42 server.createAnalysisServer(channel2); 44 server.createAnalysisServer(channel2);
43 channel1.expectMsgCount(notificationCount: 1); 45 channel1.expectMsgCount(notificationCount: 1);
44 channel2.expectMsgCount(responseCount: 1); 46 channel2.expectMsgCount(responseCount: 1);
45 expect(channel2.responsesReceived[0].id, equals('')); 47 expect(channel2.responsesReceived[0].id, equals(''));
46 expect(channel2.responsesReceived[0].error, isNotNull); 48 expect(channel2.responsesReceived[0].error, isNotNull);
47 expect( 49 expect(
48 channel2.responsesReceived[0].error.code, 50 channel2.responsesReceived[0].error.code,
49 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); 51 equals(RequestErrorCode.SERVER_ALREADY_STARTED));
50 channel2.sendRequest( 52 channel2.sendRequest(
51 new ServerShutdownParams().toRequest('0')).then((Response response) { 53 new ServerShutdownParams().toRequest('0')).then((Response response) {
52 expect(response.id, equals('0')); 54 expect(response.id, equals('0'));
53 expect(response.error, isNotNull); 55 expect(response.error, isNotNull);
54 expect( 56 expect(
55 response.error.code, 57 response.error.code,
56 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); 58 equals(RequestErrorCode.SERVER_ALREADY_STARTED));
57 channel2.expectMsgCount(responseCount: 2); 59 channel2.expectMsgCount(responseCount: 2);
58 }); 60 });
59 } 61 }
60 62
61 static Future createAnalysisServer_successful() { 63 static Future createAnalysisServer_successful() {
62 SocketServer server = new SocketServer( 64 SocketServer server = new SocketServer(
63 new AnalysisServerOptions(), 65 new AnalysisServerOptions(),
64 DirectoryBasedDartSdk.defaultSdk); 66 DirectoryBasedDartSdk.defaultSdk,
67 new NullInstrumentationServer());
65 MockServerChannel channel = new MockServerChannel(); 68 MockServerChannel channel = new MockServerChannel();
66 server.createAnalysisServer(channel); 69 server.createAnalysisServer(channel);
67 channel.expectMsgCount(notificationCount: 1); 70 channel.expectMsgCount(notificationCount: 1);
68 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); 71 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED);
69 return channel.sendRequest( 72 return channel.sendRequest(
70 new ServerShutdownParams().toRequest('0')).then((Response response) { 73 new ServerShutdownParams().toRequest('0')).then((Response response) {
71 expect(response.id, equals('0')); 74 expect(response.id, equals('0'));
72 expect(response.error, isNull); 75 expect(response.error, isNull);
73 channel.expectMsgCount(responseCount: 1, notificationCount: 1); 76 channel.expectMsgCount(responseCount: 1, notificationCount: 1);
74 }); 77 });
75 } 78 }
76 79
77 static Future requestHandler_exception() { 80 static Future requestHandler_exception() {
78 SocketServer server = new SocketServer( 81 SocketServer server = new SocketServer(
79 new AnalysisServerOptions(), 82 new AnalysisServerOptions(),
80 DirectoryBasedDartSdk.defaultSdk); 83 DirectoryBasedDartSdk.defaultSdk,
84 new NullInstrumentationServer());
81 MockServerChannel channel = new MockServerChannel(); 85 MockServerChannel channel = new MockServerChannel();
82 server.createAnalysisServer(channel); 86 server.createAnalysisServer(channel);
83 channel.expectMsgCount(notificationCount: 1); 87 channel.expectMsgCount(notificationCount: 1);
84 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); 88 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED);
85 _MockRequestHandler handler = new _MockRequestHandler(false); 89 _MockRequestHandler handler = new _MockRequestHandler(false);
86 server.analysisServer.handlers = [handler]; 90 server.analysisServer.handlers = [handler];
87 var request = new ServerGetVersionParams().toRequest('0'); 91 var request = new ServerGetVersionParams().toRequest('0');
88 return channel.sendRequest(request).then((Response response) { 92 return channel.sendRequest(request).then((Response response) {
89 expect(response.id, equals('0')); 93 expect(response.id, equals('0'));
90 expect(response.error, isNotNull); 94 expect(response.error, isNotNull);
91 expect(response.error.code, equals(RequestErrorCode.SERVER_ERROR)); 95 expect(response.error.code, equals(RequestErrorCode.SERVER_ERROR));
92 expect(response.error.message, equals('mock request exception')); 96 expect(response.error.message, equals('mock request exception'));
93 expect(response.error.stackTrace, isNotNull); 97 expect(response.error.stackTrace, isNotNull);
94 expect(response.error.stackTrace, isNot(isEmpty)); 98 expect(response.error.stackTrace, isNot(isEmpty));
95 channel.expectMsgCount(responseCount: 1, notificationCount: 1); 99 channel.expectMsgCount(responseCount: 1, notificationCount: 1);
96 }); 100 });
97 } 101 }
98 102
99 static Future requestHandler_futureException() { 103 static Future requestHandler_futureException() {
100 SocketServer server = new SocketServer( 104 SocketServer server = new SocketServer(
101 new AnalysisServerOptions(), 105 new AnalysisServerOptions(),
102 DirectoryBasedDartSdk.defaultSdk); 106 DirectoryBasedDartSdk.defaultSdk,
107 new NullInstrumentationServer());
103 MockServerChannel channel = new MockServerChannel(); 108 MockServerChannel channel = new MockServerChannel();
104 server.createAnalysisServer(channel); 109 server.createAnalysisServer(channel);
105 _MockRequestHandler handler = new _MockRequestHandler(true); 110 _MockRequestHandler handler = new _MockRequestHandler(true);
106 server.analysisServer.handlers = [handler]; 111 server.analysisServer.handlers = [handler];
107 var request = new ServerGetVersionParams().toRequest('0'); 112 var request = new ServerGetVersionParams().toRequest('0');
108 return channel.sendRequest(request).then((Response response) { 113 return channel.sendRequest(request).then((Response response) {
109 expect(response.id, equals('0')); 114 expect(response.id, equals('0'));
110 expect(response.error, isNull); 115 expect(response.error, isNull);
111 channel.expectMsgCount(responseCount: 1, notificationCount: 2); 116 channel.expectMsgCount(responseCount: 1, notificationCount: 2);
112 expect(channel.notificationsReceived[1].event, SERVER_ERROR); 117 expect(channel.notificationsReceived[1].event, SERVER_ERROR);
(...skipping 12 matching lines...) Expand all
125 new Future(throwException); 130 new Future(throwException);
126 return new Response(request.id); 131 return new Response(request.id);
127 } 132 }
128 throw 'mock request exception'; 133 throw 'mock request exception';
129 } 134 }
130 135
131 void throwException() { 136 void throwException() {
132 throw 'mock future exception'; 137 throw 'mock future exception';
133 } 138 }
134 } 139 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_server_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698