| Index: pkg/analysis_server/test/channel/byte_stream_channel_test.dart
|
| diff --git a/pkg/analysis_server/test/channel/byte_stream_channel_test.dart b/pkg/analysis_server/test/channel/byte_stream_channel_test.dart
|
| index 94cdc812e141a8d17f5efb50b72de3612629a97c..827dd75ca05d766a5763dd4e88780ec81b503f62 100644
|
| --- a/pkg/analysis_server/test/channel/byte_stream_channel_test.dart
|
| +++ b/pkg/analysis_server/test/channel/byte_stream_channel_test.dart
|
| @@ -10,53 +10,49 @@ import 'package:analysis_server/protocol/protocol.dart';
|
| import 'package:analysis_server/src/channel/byte_stream_channel.dart';
|
| import 'package:analyzer/instrumentation/instrumentation.dart';
|
| import 'package:test/test.dart';
|
| +import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
| import '../mocks.dart';
|
|
|
| main() {
|
| - group('ByteStreamClientChannel', () {
|
| - setUp(ByteStreamClientChannelTest.setUp);
|
| - test('close', ByteStreamClientChannelTest.close);
|
| - test(
|
| - 'listen_notification', ByteStreamClientChannelTest.listen_notification);
|
| - test('listen_response', ByteStreamClientChannelTest.listen_response);
|
| - test('sendRequest', ByteStreamClientChannelTest.sendRequest);
|
| - });
|
| - group('ByteStreamServerChannel', () {
|
| - setUp(ByteStreamServerChannelTest.setUp);
|
| - test('closed', ByteStreamServerChannelTest.closed);
|
| - test('listen_wellFormedRequest',
|
| - ByteStreamServerChannelTest.listen_wellFormedRequest);
|
| - test('listen_invalidRequest',
|
| - ByteStreamServerChannelTest.listen_invalidRequest);
|
| - test('listen_invalidJson', ByteStreamServerChannelTest.listen_invalidJson);
|
| - test('listen_streamError', ByteStreamServerChannelTest.listen_streamError);
|
| - test('listen_streamDone', ByteStreamServerChannelTest.listen_streamDone);
|
| - test('sendNotification', ByteStreamServerChannelTest.sendNotification);
|
| - test('sendResponse', ByteStreamServerChannelTest.sendResponse);
|
| + defineReflectiveSuite(() {
|
| + defineReflectiveTests(ByteStreamClientChannelTest);
|
| + defineReflectiveTests(ByteStreamServerChannelTest);
|
| });
|
| }
|
|
|
| +@reflectiveTest
|
| class ByteStreamClientChannelTest {
|
| - static ByteStreamClientChannel channel;
|
| + ByteStreamClientChannel channel;
|
|
|
| /**
|
| * Sink that may be used to deliver data to the channel, as though it's
|
| * coming from the server.
|
| */
|
| - static IOSink inputSink;
|
| + IOSink inputSink;
|
|
|
| /**
|
| * Sink through which the channel delivers data to the server.
|
| */
|
| - static IOSink outputSink;
|
| + IOSink outputSink;
|
|
|
| /**
|
| * Stream of lines sent back to the client by the channel.
|
| */
|
| - static Stream<String> outputLineStream;
|
| + Stream<String> outputLineStream;
|
|
|
| - static Future close() {
|
| + void setUp() {
|
| + var inputStream = new StreamController<List<int>>();
|
| + inputSink = new IOSink(inputStream);
|
| + var outputStream = new StreamController<List<int>>();
|
| + outputLineStream = outputStream.stream
|
| + .transform((new Utf8Codec()).decoder)
|
| + .transform(new LineSplitter());
|
| + outputSink = new IOSink(outputStream);
|
| + channel = new ByteStreamClientChannel(inputStream.stream, outputSink);
|
| + }
|
| +
|
| + test_close() {
|
| bool doneCalled = false;
|
| bool closeCalled = false;
|
| // add listener so that outputSink will trigger done/close futures
|
| @@ -73,7 +69,7 @@ class ByteStreamClientChannelTest {
|
| });
|
| }
|
|
|
| - static Future listen_notification() {
|
| + test_listen_notification() {
|
| List<Notification> notifications = [];
|
| channel.notificationStream.forEach((n) => notifications.add(n));
|
| inputSink.writeln('{"event":"server.connected"}');
|
| @@ -83,7 +79,7 @@ class ByteStreamClientChannelTest {
|
| });
|
| }
|
|
|
| - static Future listen_response() {
|
| + test_listen_response() {
|
| List<Response> responses = [];
|
| channel.responseStream.forEach((n) => responses.add(n));
|
| inputSink.writeln('{"id":"72"}');
|
| @@ -93,7 +89,7 @@ class ByteStreamClientChannelTest {
|
| });
|
| }
|
|
|
| - static Future sendRequest() {
|
| + test_sendRequest() {
|
| int assertCount = 0;
|
| Request request = new Request('72', 'foo.bar');
|
| outputLineStream.first.then((line) => JSON.decode(line)).then((json) {
|
| @@ -109,55 +105,72 @@ class ByteStreamClientChannelTest {
|
| });
|
| return pumpEventQueue().then((_) => expect(assertCount, equals(2)));
|
| }
|
| -
|
| - static void setUp() {
|
| - var inputStream = new StreamController<List<int>>();
|
| - inputSink = new IOSink(inputStream);
|
| - var outputStream = new StreamController<List<int>>();
|
| - outputLineStream = outputStream.stream
|
| - .transform((new Utf8Codec()).decoder)
|
| - .transform(new LineSplitter());
|
| - outputSink = new IOSink(outputStream);
|
| - channel = new ByteStreamClientChannel(inputStream.stream, outputSink);
|
| - }
|
| }
|
|
|
| +@reflectiveTest
|
| class ByteStreamServerChannelTest {
|
| - static ByteStreamServerChannel channel;
|
| + ByteStreamServerChannel channel;
|
|
|
| /**
|
| * Sink that may be used to deliver data to the channel, as though it's
|
| * coming from the client.
|
| */
|
| - static IOSink inputSink;
|
| + IOSink inputSink;
|
|
|
| /**
|
| * Stream of lines sent back to the client by the channel.
|
| */
|
| - static Stream<String> outputLineStream;
|
| + Stream<String> outputLineStream;
|
|
|
| /**
|
| * Stream of requests received from the channel via [listen()].
|
| */
|
| - static Stream<Request> requestStream;
|
| + Stream<Request> requestStream;
|
|
|
| /**
|
| * Stream of errors received from the channel via [listen()].
|
| */
|
| - static Stream errorStream;
|
| + Stream errorStream;
|
|
|
| /**
|
| * Future which is completed when then [listen()] reports [onDone].
|
| */
|
| - static Future doneFuture;
|
| + Future doneFuture;
|
|
|
| - static Future closed() {
|
| + void setUp() {
|
| + StreamController<List<int>> inputStream = new StreamController<List<int>>();
|
| + inputSink = new IOSink(inputStream);
|
| + StreamController<List<int>> outputStream =
|
| + new StreamController<List<int>>();
|
| + outputLineStream = outputStream.stream
|
| + .transform((new Utf8Codec()).decoder)
|
| + .transform(new LineSplitter());
|
| + IOSink outputSink = new IOSink(outputStream);
|
| + channel = new ByteStreamServerChannel(
|
| + inputStream.stream, outputSink, InstrumentationService.NULL_SERVICE);
|
| + StreamController<Request> requestStreamController =
|
| + new StreamController<Request>();
|
| + requestStream = requestStreamController.stream;
|
| + StreamController errorStreamController = new StreamController();
|
| + errorStream = errorStreamController.stream;
|
| + Completer doneCompleter = new Completer();
|
| + doneFuture = doneCompleter.future;
|
| + channel.listen((Request request) {
|
| + requestStreamController.add(request);
|
| + }, onError: (error) {
|
| + errorStreamController.add(error);
|
| + }, onDone: () {
|
| + doneCompleter.complete();
|
| + });
|
| + }
|
| +
|
| + test_closed() {
|
| return inputSink
|
| .close()
|
| .then((_) => channel.closed.timeout(new Duration(seconds: 1)));
|
| }
|
|
|
| - static Future listen_invalidJson() {
|
| + test_listen_invalidJson() {
|
| inputSink.writeln('{"id":');
|
| return inputSink
|
| .flush()
|
| @@ -170,7 +183,7 @@ class ByteStreamServerChannelTest {
|
| });
|
| }
|
|
|
| - static Future listen_invalidRequest() {
|
| + test_listen_invalidRequest() {
|
| inputSink.writeln('{"id":"0"}');
|
| return inputSink
|
| .flush()
|
| @@ -183,13 +196,13 @@ class ByteStreamServerChannelTest {
|
| });
|
| }
|
|
|
| - static Future listen_streamDone() {
|
| + test_listen_streamDone() {
|
| return inputSink
|
| .close()
|
| .then((_) => doneFuture.timeout(new Duration(seconds: 1)));
|
| }
|
|
|
| - static Future listen_streamError() {
|
| + test_listen_streamError() {
|
| var error = new Error();
|
| inputSink.addError(error);
|
| return inputSink
|
| @@ -200,7 +213,7 @@ class ByteStreamServerChannelTest {
|
| });
|
| }
|
|
|
| - static Future listen_wellFormedRequest() {
|
| + test_listen_wellFormedRequest() {
|
| inputSink.writeln('{"id":"0","method":"server.version"}');
|
| return inputSink
|
| .flush()
|
| @@ -211,7 +224,7 @@ class ByteStreamServerChannelTest {
|
| });
|
| }
|
|
|
| - static Future sendNotification() {
|
| + test_sendNotification() {
|
| channel.sendNotification(new Notification('foo'));
|
| return outputLineStream.first
|
| .timeout(new Duration(seconds: 1))
|
| @@ -223,7 +236,7 @@ class ByteStreamServerChannelTest {
|
| });
|
| }
|
|
|
| - static Future sendResponse() {
|
| + test_sendResponse() {
|
| channel.sendResponse(new Response('foo'));
|
| return outputLineStream.first
|
| .timeout(new Duration(seconds: 1))
|
| @@ -234,31 +247,4 @@ class ByteStreamServerChannelTest {
|
| expect(jsonResponse['id'], equals('foo'));
|
| });
|
| }
|
| -
|
| - static void setUp() {
|
| - StreamController<List<int>> inputStream = new StreamController<List<int>>();
|
| - inputSink = new IOSink(inputStream);
|
| - StreamController<List<int>> outputStream =
|
| - new StreamController<List<int>>();
|
| - outputLineStream = outputStream.stream
|
| - .transform((new Utf8Codec()).decoder)
|
| - .transform(new LineSplitter());
|
| - IOSink outputSink = new IOSink(outputStream);
|
| - channel = new ByteStreamServerChannel(
|
| - inputStream.stream, outputSink, InstrumentationService.NULL_SERVICE);
|
| - StreamController<Request> requestStreamController =
|
| - new StreamController<Request>();
|
| - requestStream = requestStreamController.stream;
|
| - StreamController errorStreamController = new StreamController();
|
| - errorStream = errorStreamController.stream;
|
| - Completer doneCompleter = new Completer();
|
| - doneFuture = doneCompleter.future;
|
| - channel.listen((Request request) {
|
| - requestStreamController.add(request);
|
| - }, onError: (error) {
|
| - errorStreamController.add(error);
|
| - }, onDone: () {
|
| - doneCompleter.complete();
|
| - });
|
| - }
|
| }
|
|
|