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

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

Issue 284353002: implement ByteStreamClientChannel close (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge 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
(...skipping 10 matching lines...) Expand all
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', () { 29 group('ByteStreamClientChannel', () {
30 setUp(ByteStreamClientChannelTest.setUp); 30 setUp(ByteStreamClientChannelTest.setUp);
31 test('close', ByteStreamClientChannelTest.close);
31 test('listen_notification', ByteStreamClientChannelTest.listen_notification) ; 32 test('listen_notification', ByteStreamClientChannelTest.listen_notification) ;
32 test('listen_response', ByteStreamClientChannelTest.listen_response); 33 test('listen_response', ByteStreamClientChannelTest.listen_response);
33 test('sendRequest', ByteStreamClientChannelTest.sendRequest); 34 test('sendRequest', ByteStreamClientChannelTest.sendRequest);
34 }); 35 });
35 group('ByteStreamServerChannel', () { 36 group('ByteStreamServerChannel', () {
36 setUp(ByteStreamServerChannelTest.setUp); 37 setUp(ByteStreamServerChannelTest.setUp);
37 test('closed', ByteStreamServerChannelTest.closed); 38 test('closed', ByteStreamServerChannelTest.closed);
38 test('listen_wellFormedRequest', 39 test('listen_wellFormedRequest',
39 ByteStreamServerChannelTest.listen_wellFormedRequest); 40 ByteStreamServerChannelTest.listen_wellFormedRequest);
40 test('listen_invalidRequest', 41 test('listen_invalidRequest',
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 expect(responsesReceived, hasLength(responseCount)); 178 expect(responsesReceived, hasLength(responseCount));
178 expect(notificationsReceived, hasLength(notificationCount)); 179 expect(notificationsReceived, hasLength(notificationCount));
179 } 180 }
180 } 181 }
181 182
182 class ByteStreamClientChannelTest { 183 class ByteStreamClientChannelTest {
183 static ByteStreamClientChannel channel; 184 static ByteStreamClientChannel channel;
184 185
185 /** 186 /**
186 * Sink that may be used to deliver data to the channel, as though it's 187 * Sink that may be used to deliver data to the channel, as though it's
187 * coming from the client. 188 * coming from the server.
188 */ 189 */
189 static IOSink inputSink; 190 static IOSink inputSink;
190 191
191 /** 192 /**
193 * Sink through which the channel delivers data to the server.
194 */
195 static IOSink outputSink;
196
197 /**
192 * Stream of lines sent back to the client by the channel. 198 * Stream of lines sent back to the client by the channel.
193 */ 199 */
194 static Stream<String> outputLineStream; 200 static Stream<String> outputLineStream;
195 201
196 static void setUp() { 202 static void setUp() {
197 var inputStream = new StreamController<List<int>>(); 203 var inputStream = new StreamController<List<int>>();
198 inputSink = new IOSink(inputStream); 204 inputSink = new IOSink(inputStream);
199 var outputStream = new StreamController<List<int>>(); 205 var outputStream = new StreamController<List<int>>();
200 outputLineStream = outputStream.stream.transform((new Utf8Codec()).decoder 206 outputLineStream = outputStream.stream.transform((new Utf8Codec()).decoder
201 ).transform(new LineSplitter()); 207 ).transform(new LineSplitter());
202 var outputSink = new IOSink(outputStream); 208 outputSink = new IOSink(outputStream);
203 channel = new ByteStreamClientChannel(inputStream.stream, outputSink); 209 channel = new ByteStreamClientChannel(inputStream.stream, outputSink);
204 } 210 }
205 211
212 static Future close() {
213 bool doneCalled = false;
214 bool closeCalled = false;
215 // add listener so that outputSink will trigger done/close futures
216 outputLineStream.listen((_) { /* no-op */ });
217 outputSink.done.then((_) {
218 doneCalled = true;
219 });
220 channel.close().then((_) {
221 closeCalled = true;
222 });
223 return pumpEventQueue().then((_) {
224 expect(doneCalled, isTrue);
225 expect(closeCalled, isTrue);
226 });
227 }
228
206 static Future listen_notification() { 229 static Future listen_notification() {
207 List<Notification> notifications = []; 230 List<Notification> notifications = [];
208 channel.notificationStream.forEach((n) => notifications.add(n)); 231 channel.notificationStream.forEach((n) => notifications.add(n));
209 inputSink.writeln('{"event":"server.connected"}'); 232 inputSink.writeln('{"event":"server.connected"}');
210 return pumpEventQueue().then((_) { 233 return pumpEventQueue().then((_) {
211 expect(notifications.length, equals(1)); 234 expect(notifications.length, equals(1));
212 expect(notifications[0].event, equals('server.connected')); 235 expect(notifications[0].event, equals('server.connected'));
213 }); 236 });
214 } 237 }
215 238
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 channel.sendResponse(new Response('foo')); 386 channel.sendResponse(new Response('foo'));
364 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String 387 return outputLineStream.first.timeout(new Duration(seconds: 1)).then((String
365 response) { 388 response) {
366 var jsonResponse = new JsonCodec().decode(response); 389 var jsonResponse = new JsonCodec().decode(response);
367 expect(jsonResponse, isMap); 390 expect(jsonResponse, isMap);
368 expect(jsonResponse, contains('id')); 391 expect(jsonResponse, contains('id'));
369 expect(jsonResponse['id'], equals('foo')); 392 expect(jsonResponse['id'], equals('foo'));
370 }); 393 });
371 } 394 }
372 } 395 }
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