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

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: revise tests to use pumpEventQueue rather than timeout 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 pumpEventQueue().then((_) {
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 pumpEventQueue().then((_) {
221 expect(responses.length, equals(1));
222 expect(responses[0].id, equals('72'));
223 });
224 }
225
226 static Future sendRequest() {
227 int assertCount = 0;
228 Request request = new Request('72', 'foo.bar');
229 outputLineStream.first
230 .then((line) => new JsonDecoder().convert(line))
231 .then((json) {
232 expect(json[Request.ID], equals('72'));
233 expect(json[Request.METHOD], equals('foo.bar'));
234 inputSink.writeln('{"id":"73"}');
235 inputSink.writeln('{"id":"72"}');
236 assertCount++;
237 });
238 channel.sendRequest(request)
239 .then((Response response) {
240 expect(response.id, equals('72'));
241 assertCount++;
242 });
243 return pumpEventQueue().then((_) => expect(assertCount, equals(2)));
244 }
245 }
246
176 class ByteStreamServerChannelTest { 247 class ByteStreamServerChannelTest {
177 static ByteStreamServerChannel channel; 248 static ByteStreamServerChannel channel;
178 249
179 /** 250 /**
180 * Sink that may be used to deliver data to the channel, as though it's 251 * Sink that may be used to deliver data to the channel, as though it's
181 * coming from the client. 252 * coming from the client.
182 */ 253 */
183 static IOSink inputSink; 254 static IOSink inputSink;
184 255
185 /** 256 /**
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 channel.sendResponse(new Response('foo')); 363 channel.sendResponse(new Response('foo'));
293 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String 364 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String
294 response) { 365 response) {
295 var jsonResponse = new JsonCodec().decode(response); 366 var jsonResponse = new JsonCodec().decode(response);
296 expect(jsonResponse, isMap); 367 expect(jsonResponse, isMap);
297 expect(jsonResponse, contains('id')); 368 expect(jsonResponse, contains('id'));
298 expect(jsonResponse['id'], equals('foo')); 369 expect(jsonResponse['id'], equals('foo'));
299 }); 370 });
300 } 371 }
301 } 372 }
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