OLD | NEW |
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.byte_stream; | 5 library test.channel.byte_stream; |
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/byte_stream_channel.dart'; | 11 import 'package:analysis_server/src/channel/byte_stream_channel.dart'; |
12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
13 import 'package:analyzer/instrumentation/instrumentation.dart'; | 13 import 'package:analyzer/instrumentation/instrumentation.dart'; |
14 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
15 | 15 |
16 import '../mocks.dart'; | 16 import '../mocks.dart'; |
| 17 import '../utils.dart'; |
17 | 18 |
18 main() { | 19 main() { |
| 20 initializeTestEnvironment(); |
19 group('ByteStreamClientChannel', () { | 21 group('ByteStreamClientChannel', () { |
20 setUp(ByteStreamClientChannelTest.setUp); | 22 setUp(ByteStreamClientChannelTest.setUp); |
21 test('close', ByteStreamClientChannelTest.close); | 23 test('close', ByteStreamClientChannelTest.close); |
22 test( | 24 test( |
23 'listen_notification', ByteStreamClientChannelTest.listen_notification); | 25 'listen_notification', ByteStreamClientChannelTest.listen_notification); |
24 test('listen_response', ByteStreamClientChannelTest.listen_response); | 26 test('listen_response', ByteStreamClientChannelTest.listen_response); |
25 test('sendRequest', ByteStreamClientChannelTest.sendRequest); | 27 test('sendRequest', ByteStreamClientChannelTest.sendRequest); |
26 }); | 28 }); |
27 group('ByteStreamServerChannel', () { | 29 group('ByteStreamServerChannel', () { |
28 setUp(ByteStreamServerChannelTest.setUp); | 30 setUp(ByteStreamServerChannelTest.setUp); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 .flush() | 210 .flush() |
209 .then((_) => requestStream.first.timeout(new Duration(seconds: 1))) | 211 .then((_) => requestStream.first.timeout(new Duration(seconds: 1))) |
210 .then((Request request) { | 212 .then((Request request) { |
211 expect(request.id, equals("0")); | 213 expect(request.id, equals("0")); |
212 expect(request.method, equals("server.version")); | 214 expect(request.method, equals("server.version")); |
213 }); | 215 }); |
214 } | 216 } |
215 | 217 |
216 static Future sendNotification() { | 218 static Future sendNotification() { |
217 channel.sendNotification(new Notification('foo')); | 219 channel.sendNotification(new Notification('foo')); |
218 return outputLineStream.first.timeout(new Duration(seconds: 1)).then( | 220 return outputLineStream.first |
219 (String notification) { | 221 .timeout(new Duration(seconds: 1)) |
| 222 .then((String notification) { |
220 var jsonNotification = new JsonCodec().decode(notification); | 223 var jsonNotification = new JsonCodec().decode(notification); |
221 expect(jsonNotification, isMap); | 224 expect(jsonNotification, isMap); |
222 expect(jsonNotification, contains('event')); | 225 expect(jsonNotification, contains('event')); |
223 expect(jsonNotification['event'], equals('foo')); | 226 expect(jsonNotification['event'], equals('foo')); |
224 }); | 227 }); |
225 } | 228 } |
226 | 229 |
227 static Future sendResponse() { | 230 static Future sendResponse() { |
228 channel.sendResponse(new Response('foo')); | 231 channel.sendResponse(new Response('foo')); |
229 return outputLineStream.first.timeout(new Duration(seconds: 1)).then( | 232 return outputLineStream.first |
230 (String response) { | 233 .timeout(new Duration(seconds: 1)) |
| 234 .then((String response) { |
231 var jsonResponse = new JsonCodec().decode(response); | 235 var jsonResponse = new JsonCodec().decode(response); |
232 expect(jsonResponse, isMap); | 236 expect(jsonResponse, isMap); |
233 expect(jsonResponse, contains('id')); | 237 expect(jsonResponse, contains('id')); |
234 expect(jsonResponse['id'], equals('foo')); | 238 expect(jsonResponse['id'], equals('foo')); |
235 }); | 239 }); |
236 } | 240 } |
237 | 241 |
238 static void setUp() { | 242 static void setUp() { |
239 StreamController<List<int>> inputStream = new StreamController<List<int>>(); | 243 StreamController<List<int>> inputStream = new StreamController<List<int>>(); |
240 inputSink = new IOSink(inputStream); | 244 inputSink = new IOSink(inputStream); |
(...skipping 14 matching lines...) Expand all Loading... |
255 doneFuture = doneCompleter.future; | 259 doneFuture = doneCompleter.future; |
256 channel.listen((Request request) { | 260 channel.listen((Request request) { |
257 requestStreamController.add(request); | 261 requestStreamController.add(request); |
258 }, onError: (error) { | 262 }, onError: (error) { |
259 errorStreamController.add(error); | 263 errorStreamController.add(error); |
260 }, onDone: () { | 264 }, onDone: () { |
261 doneCompleter.complete(); | 265 doneCompleter.complete(); |
262 }); | 266 }); |
263 } | 267 } |
264 } | 268 } |
OLD | NEW |