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

Unified Diff: pkg/analysis_server/test/integration/integration_tests.dart

Issue 418033006: Handle bad data in analysis server integration tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/integration/integration_tests.dart
diff --git a/pkg/analysis_server/test/integration/integration_tests.dart b/pkg/analysis_server/test/integration/integration_tests.dart
index 72cd511a83d2d9c86e4539693058d0c3dedadd11..af863fd5152ed510c067c62195160584ed13235a 100644
--- a/pkg/analysis_server/test/integration/integration_tests.dart
+++ b/pkg/analysis_server/test/integration/integration_tests.dart
@@ -471,6 +471,12 @@ class Server {
*/
bool _debuggingStdio = false;
+ /**
+ * True if we've received bad data from the server, and we are aborting the
+ * test.
+ */
+ bool _receivedBadDataFromServer = false;
+
Server._(this._process);
/**
@@ -524,7 +530,13 @@ class Server {
new LineSplitter()).listen((String line) {
String trimmedLine = line.trim();
server._recordStdio('RECV: $trimmedLine');
- var message = JSON.decoder.convert(trimmedLine);
+ var message;
+ try {
+ message = JSON.decoder.convert(trimmedLine);
+ } catch (exception) {
+ server._badDataFromServer();
+ return;
+ }
expect(message, isMap);
Map messageAsMap = message;
if (messageAsMap.containsKey('id')) {
@@ -564,8 +576,11 @@ class Server {
expect(message, isNotification);
}
});
- process.stderr.listen((List<int> data) {
- fail('Unexpected output from stderr');
+ process.stderr.transform((new Utf8Codec()).decoder).transform(
+ new LineSplitter()).listen((String line) {
+ String trimmedLine = line.trim();
+ server._recordStdio('ERR: $trimmedLine');
+ server._badDataFromServer();
});
return server;
});
@@ -619,6 +634,26 @@ class Server {
}
/**
+ * Deal with bad data received from the server.
+ */
+ void _badDataFromServer() {
+ if (_receivedBadDataFromServer) {
+ // We're already dealing with it.
+ return;
+ }
+ _receivedBadDataFromServer = true;
+ debugStdio();
+ // Give the server 1 second to continue outputting bad data before we kill
+ // the test. This is helpful if the server has had an unhandled exception
+ // and is outputting a stacktrace, because it ensures that we see the
+ // entire stacktrace. Use expectAsync() to prevent the test from
+ // ending during this 1 second.
+ new Future.delayed(new Duration(seconds: 1), expectAsync(() {
+ fail('Bad data received from server');
+ }));
+ }
+
+ /**
* Record a message that was exchanged with the server, and print it out if
* [debugStdio] has been called.
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698