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

Unified Diff: pkg/analysis_server/test/socket_server_test.dart

Issue 570453002: gracefully handle internal exceptions during request (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/socket_server_test.dart
diff --git a/pkg/analysis_server/test/socket_server_test.dart b/pkg/analysis_server/test/socket_server_test.dart
index 5fcd0e61c05f850d96e9412ceeb2b20ceb10f30b..288d33f35e779eb955f5069c7274b5d6eea7459c 100644
--- a/pkg/analysis_server/test/socket_server_test.dart
+++ b/pkg/analysis_server/test/socket_server_test.dart
@@ -20,6 +20,9 @@ main() {
SocketServerTest.createAnalysisServer_successful);
test('createAnalysisServer_alreadyStarted',
SocketServerTest.createAnalysisServer_alreadyStarted);
+ test('requestHandler_exception', SocketServerTest.requestHandler_exception);
+ test('requestHandler_futureException',
+ SocketServerTest.requestHandler_futureException);
});
}
@@ -61,4 +64,54 @@ class SocketServerTest {
channel2.expectMsgCount(responseCount: 2);
});
}
+
+ static Future requestHandler_exception() {
+ SocketServer server = new SocketServer(DirectoryBasedDartSdk.defaultSdk);
+ MockServerChannel channel = new MockServerChannel();
+ server.createAnalysisServer(channel);
+ _MockRequestHandler handler = new _MockRequestHandler(false);
+ server.analysisServer.handlers = [handler];
+ var request = new ServerGetVersionParams().toRequest('0');
+ return channel.sendRequest(request).then((Response response) {
+ expect(response.id, equals('0'));
+ expect(response.error, isNotNull);
+ expect(response.error.code, equals(RequestErrorCode.SERVER_ERROR));
+ channel.expectMsgCount(responseCount: 1, notificationCount: 2);
+ expect(channel.notificationsReceived[1].event, SERVER_ERROR);
+ });
+ }
+
+ static Future requestHandler_futureException() {
+ SocketServer server = new SocketServer(DirectoryBasedDartSdk.defaultSdk);
+ MockServerChannel channel = new MockServerChannel();
+ server.createAnalysisServer(channel);
+ _MockRequestHandler handler = new _MockRequestHandler(true);
+ server.analysisServer.handlers = [handler];
+ var request = new ServerGetVersionParams().toRequest('0');
+ return channel.sendRequest(request).then((Response response) {
+ expect(response.id, equals('0'));
+ expect(response.error, isNull);
+ channel.expectMsgCount(responseCount: 1, notificationCount: 2);
+ expect(channel.notificationsReceived[1].event, SERVER_ERROR);
+ });
+ }
+}
+
+class _MockRequestHandler implements RequestHandler {
+ final bool futureException;
+
+ _MockRequestHandler(this.futureException);
+
+ @override
+ Response handleRequest(Request request) {
+ if (futureException) {
+ new Future(throwException);
+ return new Response(request.id);
+ }
+ throw 'mock request exception';
+ }
+
+ void throwException() {
+ throw 'mock future exception';
+ }
}
« no previous file with comments | « pkg/analysis_server/test/integration/protocol_matchers.dart ('k') | pkg/analysis_server/tool/spec/spec_input.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698