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

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

Issue 276113002: new ByteStreamClientChannel (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/channel.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.channel; 5 library test.channel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analysis_server/src/channel.dart'; 11 import 'package:analysis_server/src/channel.dart';
12 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 import 'mocks.dart'; 15 import 'mocks.dart';
16 16
17 main() { 17 main() {
18 group('WebSocketChannel', () { 18 group('WebSocketChannel', () {
19 setUp(WebSocketChannelTest.setUp); 19 setUp(WebSocketChannelTest.setUp);
20 test('close', WebSocketChannelTest.close); 20 test('close', WebSocketChannelTest.close);
21 test('invalidJsonToClient', WebSocketChannelTest.invalidJsonToClient); 21 test('invalidJsonToClient', WebSocketChannelTest.invalidJsonToClient);
22 test('invalidJsonToServer', WebSocketChannelTest.invalidJsonToServer); 22 test('invalidJsonToServer', WebSocketChannelTest.invalidJsonToServer);
23 test('notification', WebSocketChannelTest.notification); 23 test('notification', WebSocketChannelTest.notification);
24 test('notificationAndResponse', WebSocketChannelTest.notificationAndResponse ); 24 test('notificationAndResponse', WebSocketChannelTest.notificationAndResponse );
25 test('request', WebSocketChannelTest.request); 25 test('request', WebSocketChannelTest.request);
26 test('requestResponse', WebSocketChannelTest.requestResponse); 26 test('requestResponse', WebSocketChannelTest.requestResponse);
27 test('response', WebSocketChannelTest.response); 27 test('response', WebSocketChannelTest.response);
28 }); 28 });
29 group('ByteStreamClientChannel', () {
30 setUp(ByteStreamClientChannelTest.setUp);
31 test('listen_notification', ByteStreamClientChannelTest.listen_notification) ;
32 test('listen_response', ByteStreamClientChannelTest.listen_response);
33 test('sendRequest', ByteStreamClientChannelTest.sendRequest);
34 });
29 group('ByteStreamServerChannel', () { 35 group('ByteStreamServerChannel', () {
30 setUp(ByteStreamServerChannelTest.setUp); 36 setUp(ByteStreamServerChannelTest.setUp);
31 test('closed', ByteStreamServerChannelTest.closed); 37 test('closed', ByteStreamServerChannelTest.closed);
32 test('listen_wellFormedRequest', 38 test('listen_wellFormedRequest',
33 ByteStreamServerChannelTest.listen_wellFormedRequest); 39 ByteStreamServerChannelTest.listen_wellFormedRequest);
34 test('listen_invalidRequest', 40 test('listen_invalidRequest',
35 ByteStreamServerChannelTest.listen_invalidRequest); 41 ByteStreamServerChannelTest.listen_invalidRequest);
36 test('listen_invalidJson', ByteStreamServerChannelTest.listen_invalidJson); 42 test('listen_invalidJson', ByteStreamServerChannelTest.listen_invalidJson);
37 test('listen_streamError', ByteStreamServerChannelTest.listen_streamError); 43 test('listen_streamError', ByteStreamServerChannelTest.listen_streamError);
38 test('listen_streamDone', ByteStreamServerChannelTest.listen_streamDone); 44 test('listen_streamDone', ByteStreamServerChannelTest.listen_streamDone);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 172
167 static void expectMsgCount({requestCount: 0, 173 static void expectMsgCount({requestCount: 0,
168 responseCount: 0, 174 responseCount: 0,
169 notificationCount: 0}) { 175 notificationCount: 0}) {
170 expect(requestsReceived, hasLength(requestCount)); 176 expect(requestsReceived, hasLength(requestCount));
171 expect(responsesReceived, hasLength(responseCount)); 177 expect(responsesReceived, hasLength(responseCount));
172 expect(notificationsReceived, hasLength(notificationCount)); 178 expect(notificationsReceived, hasLength(notificationCount));
173 } 179 }
174 } 180 }
175 181
182 class ByteStreamClientChannelTest {
183 static ByteStreamClientChannel channel;
184
185 /**
186 * Sink that may be used to deliver data to the channel, as though it's
187 * coming from the client.
188 */
189 static IOSink inputSink;
190
191 /**
192 * Stream of lines sent back to the client by the channel.
193 */
194 static Stream<String> outputLineStream;
195
196 static void setUp() {
197 var inputStream = new StreamController<List<int>>();
198 inputSink = new IOSink(inputStream);
199 var outputStream = new StreamController<List<int>>();
200 outputLineStream = outputStream.stream.transform((new Utf8Codec()).decoder
201 ).transform(new LineSplitter());
202 var outputSink = new IOSink(outputStream);
203 channel = new ByteStreamClientChannel(inputStream.stream, outputSink);
204 }
205
206 static Future listen_notification() {
207 List<Notification> notifications = [];
208 channel.notificationStream.forEach((n) => notifications.add(n));
209 inputSink.writeln('{"event":"server.connected"}');
210 return inputSink.flush().timeout(new Duration(seconds: 1)).then((_) {
Paul Berry 2014/05/11 05:09:00 Using timeouts like this leads to nondeterministic
danrubel 2014/05/12 20:16:25 Good idea. Done.
211 expect(notifications.length, equals(1));
212 expect(notifications[0].event, equals('server.connected'));
213 });
214 }
215
216 static Future listen_response() {
217 List<Response> responses = [];
218 channel.responseStream.forEach((n) => responses.add(n));
219 inputSink.writeln('{"id":"72"}');
220 return inputSink.flush().timeout(new Duration(seconds: 1)).then((_) {
221 expect(responses.length, equals(1));
222 expect(responses[0].id, equals('72'));
223 });
224 }
225
226 static Future sendRequest() {
227 Request request = new Request('72', 'foo.bar');
228 outputLineStream.first.timeout(new Duration(seconds: 1))
229 .then((line) => new JsonDecoder().convert(line))
230 .then((json) {
231 expect(json[Request.ID], equals('72'));
232 expect(json[Request.METHOD], equals('foo.bar'));
233 inputSink.writeln('{"id":"73"}');
234 inputSink.writeln('{"id":"72"}');
235 });
236 return channel.sendRequest(request).timeout(new Duration(seconds: 1))
237 .then((Response response) {
238 expect(response.id, equals('72'));
239 });
240 }
241 }
242
176 class ByteStreamServerChannelTest { 243 class ByteStreamServerChannelTest {
177 static ByteStreamServerChannel channel; 244 static ByteStreamServerChannel channel;
178 245
179 /** 246 /**
180 * Sink that may be used to deliver data to the channel, as though it's 247 * Sink that may be used to deliver data to the channel, as though it's
181 * coming from the client. 248 * coming from the client.
182 */ 249 */
183 static IOSink inputSink; 250 static IOSink inputSink;
184 251
185 /** 252 /**
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 channel.sendResponse(new Response('foo')); 359 channel.sendResponse(new Response('foo'));
293 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String 360 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String
294 response) { 361 response) {
295 var jsonResponse = new JsonCodec().decode(response); 362 var jsonResponse = new JsonCodec().decode(response);
296 expect(jsonResponse, isMap); 363 expect(jsonResponse, isMap);
297 expect(jsonResponse, contains('id')); 364 expect(jsonResponse, contains('id'));
298 expect(jsonResponse['id'], equals('foo')); 365 expect(jsonResponse['id'], equals('foo'));
299 }); 366 });
300 } 367 }
301 } 368 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/channel.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698