| 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.socket.server; | 5 library test.socket.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| 11 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 11 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analysis_server/src/socket_server.dart'; | 13 import 'package:analysis_server/src/socket_server.dart'; |
| 14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart'; | 15 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 16 import 'package:analyzer/src/plugin/plugin_impl.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 17 | 18 |
| 18 import 'mocks.dart'; | 19 import 'mocks.dart'; |
| 19 import 'package:analysis_server/src/plugin/plugin_impl.dart'; | |
| 20 | 20 |
| 21 main() { | 21 main() { |
| 22 group('SocketServer', () { | 22 group('SocketServer', () { |
| 23 test('createAnalysisServer_successful', | 23 test('createAnalysisServer_successful', |
| 24 SocketServerTest.createAnalysisServer_successful); | 24 SocketServerTest.createAnalysisServer_successful); |
| 25 test('createAnalysisServer_alreadyStarted', | 25 test('createAnalysisServer_alreadyStarted', |
| 26 SocketServerTest.createAnalysisServer_alreadyStarted); | 26 SocketServerTest.createAnalysisServer_alreadyStarted); |
| 27 test('requestHandler_exception', SocketServerTest.requestHandler_exception); | 27 test('requestHandler_exception', SocketServerTest.requestHandler_exception); |
| 28 test('requestHandler_futureException', | 28 test('requestHandler_futureException', |
| 29 SocketServerTest.requestHandler_futureException); | 29 SocketServerTest.requestHandler_futureException); |
| 30 }); | 30 }); |
| 31 } | 31 } |
| 32 | 32 |
| 33 class SocketServerTest { | 33 class SocketServerTest { |
| 34 static void createAnalysisServer_alreadyStarted() { | 34 static void createAnalysisServer_alreadyStarted() { |
| 35 SocketServer server = _createSocketServer(); | 35 SocketServer server = _createSocketServer(); |
| 36 MockServerChannel channel1 = new MockServerChannel(); | 36 MockServerChannel channel1 = new MockServerChannel(); |
| 37 MockServerChannel channel2 = new MockServerChannel(); | 37 MockServerChannel channel2 = new MockServerChannel(); |
| 38 server.createAnalysisServer(channel1); | 38 server.createAnalysisServer(channel1); |
| 39 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED); | 39 expect(channel1.notificationsReceived[0].event, SERVER_CONNECTED); |
| 40 server.createAnalysisServer(channel2); | 40 server.createAnalysisServer(channel2); |
| 41 channel1.expectMsgCount(notificationCount: 1); | 41 channel1.expectMsgCount(notificationCount: 1); |
| 42 channel2.expectMsgCount(responseCount: 1); | 42 channel2.expectMsgCount(responseCount: 1); |
| 43 expect(channel2.responsesReceived[0].id, equals('')); | 43 expect(channel2.responsesReceived[0].id, equals('')); |
| 44 expect(channel2.responsesReceived[0].error, isNotNull); | 44 expect(channel2.responsesReceived[0].error, isNotNull); |
| 45 expect(channel2.responsesReceived[0].error.code, | 45 expect(channel2.responsesReceived[0].error.code, |
| 46 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); | 46 equals(RequestErrorCode.SERVER_ALREADY_STARTED)); |
| 47 channel2.sendRequest(new ServerShutdownParams().toRequest('0')).then( | 47 channel2 |
| 48 (Response response) { | 48 .sendRequest(new ServerShutdownParams().toRequest('0')) |
| 49 .then((Response response) { |
| 49 expect(response.id, equals('0')); | 50 expect(response.id, equals('0')); |
| 50 expect(response.error, isNotNull); | 51 expect(response.error, isNotNull); |
| 51 expect( | 52 expect( |
| 52 response.error.code, equals(RequestErrorCode.SERVER_ALREADY_STARTED)); | 53 response.error.code, equals(RequestErrorCode.SERVER_ALREADY_STARTED)); |
| 53 channel2.expectMsgCount(responseCount: 2); | 54 channel2.expectMsgCount(responseCount: 2); |
| 54 }); | 55 }); |
| 55 } | 56 } |
| 56 | 57 |
| 57 static Future createAnalysisServer_successful() { | 58 static Future createAnalysisServer_successful() { |
| 58 SocketServer server = _createSocketServer(); | 59 SocketServer server = _createSocketServer(); |
| 59 MockServerChannel channel = new MockServerChannel(); | 60 MockServerChannel channel = new MockServerChannel(); |
| 60 server.createAnalysisServer(channel); | 61 server.createAnalysisServer(channel); |
| 61 channel.expectMsgCount(notificationCount: 1); | 62 channel.expectMsgCount(notificationCount: 1); |
| 62 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); | 63 expect(channel.notificationsReceived[0].event, SERVER_CONNECTED); |
| 63 return channel.sendRequest(new ServerShutdownParams().toRequest('0')).then( | 64 return channel |
| 64 (Response response) { | 65 .sendRequest(new ServerShutdownParams().toRequest('0')) |
| 66 .then((Response response) { |
| 65 expect(response.id, equals('0')); | 67 expect(response.id, equals('0')); |
| 66 expect(response.error, isNull); | 68 expect(response.error, isNull); |
| 67 channel.expectMsgCount(responseCount: 1, notificationCount: 1); | 69 channel.expectMsgCount(responseCount: 1, notificationCount: 1); |
| 68 }); | 70 }); |
| 69 } | 71 } |
| 70 | 72 |
| 71 static Future requestHandler_exception() { | 73 static Future requestHandler_exception() { |
| 72 SocketServer server = _createSocketServer(); | 74 SocketServer server = _createSocketServer(); |
| 73 MockServerChannel channel = new MockServerChannel(); | 75 MockServerChannel channel = new MockServerChannel(); |
| 74 server.createAnalysisServer(channel); | 76 server.createAnalysisServer(channel); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 new Future(throwException); | 126 new Future(throwException); |
| 125 return new Response(request.id); | 127 return new Response(request.id); |
| 126 } | 128 } |
| 127 throw 'mock request exception'; | 129 throw 'mock request exception'; |
| 128 } | 130 } |
| 129 | 131 |
| 130 void throwException() { | 132 void throwException() { |
| 131 throw 'mock future exception'; | 133 throw 'mock future exception'; |
| 132 } | 134 } |
| 133 } | 135 } |
| OLD | NEW |