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

Side by Side Diff: pkg/analysis_server/test/analysis_server_test.dart

Issue 298823007: add server.status notification (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: reduce variable scope Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.analysis_server; 5 library test.analysis_server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 LineInfo lineInfo = new LineInfo([0]); 73 LineInfo lineInfo = new LineInfo([0]);
74 AnalysisError analysisError = new AnalysisError.con1(source, 74 AnalysisError analysisError = new AnalysisError.con1(source,
75 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, ['Foo']); 75 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, ['Foo']);
76 changeNoticeImpl.setErrors([analysisError], lineInfo); 76 changeNoticeImpl.setErrors([analysisError], lineInfo);
77 context.when(callsTo('performAnalysisTask')).thenReturn( 77 context.when(callsTo('performAnalysisTask')).thenReturn(
78 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0)); 78 new AnalysisResult([changeNoticeImpl], 0, 'myClass', 0));
79 context.when(callsTo('performAnalysisTask')).thenReturn( 79 context.when(callsTo('performAnalysisTask')).thenReturn(
80 new AnalysisResult(null, 0, null, 0)); 80 new AnalysisResult(null, 0, null, 0));
81 return pumpEventQueue().then((_) { 81 return pumpEventQueue().then((_) {
82 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2)) ; 82 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(2)) ;
83 var notifications = channel.notificationsReceived; 83 List<Notification> notifications = channel.notificationsReceived;
84 expect(notifications, hasLength(2)); 84 expect(notifications, hasLength(4));
85
85 expect(notifications[0].event, equals('server.connected')); 86 expect(notifications[0].event, equals('server.connected'));
86 expect(notifications[1].event, equals('context.errors')); 87
87 expect(notifications[1].params['source'], equals('foo.dart')); 88 assertStatusNotification(notifications[1], true);
88 expect(notifications[1].params['contextId'], equals('context-27')); 89
89 List<AnalysisError> errors = notifications[1].params['errors']; 90 expect(notifications[2].event, equals('context.errors'));
91 expect(notifications[2].params['source'], equals('foo.dart'));
92 expect(notifications[2].params['contextId'], equals('context-27'));
93 List<AnalysisError> errors = notifications[2].params['errors'];
90 expect(errors, hasLength(1)); 94 expect(errors, hasLength(1));
91 expect(errors[0], equals(AnalysisServer.errorToJson(analysisError))); 95 expect(errors[0], equals(AnalysisServer.errorToJson(analysisError)));
96
97 assertStatusNotification(notifications[3], false);
92 }); 98 });
93 } 99 }
94 100
101 static void assertStatusNotification(Notification notification, bool expectAna lyzing) {
102 expect(notification.event, equals('server.status'));
103 Map<String, Object> analysis = notification.params['analysis'];
104 expect(analysis['analyzing'], expectAnalyzing);
105 expect(analysis.containsKey('analysisTarget'), expectAnalyzing);
106 if (expectAnalyzing) {
107 var analysisTarget = analysis['analysisTarget'];
108 expect((analysisTarget is String), isTrue);
109 expect(analysisTarget.length > 0, isTrue);
110 }
111 }
112
95 static Future addContextToWorkQueue_twice() { 113 static Future addContextToWorkQueue_twice() {
96 // The context should only be asked to perform its analysis task once. 114 // The context should only be asked to perform its analysis task once.
97 MockAnalysisContext context = new MockAnalysisContext(); 115 MockAnalysisContext context = new MockAnalysisContext();
98 server.addContextToWorkQueue(context); 116 server.addContextToWorkQueue(context);
99 server.addContextToWorkQueue(context); 117 server.addContextToWorkQueue(context);
100 context.when(callsTo('performAnalysisTask')).thenReturn( 118 context.when(callsTo('performAnalysisTask')).thenReturn(
101 new AnalysisResult(null, 0, null, 0)); 119 new AnalysisResult(null, 0, null, 0));
102 return pumpEventQueue().then((_) => 120 return pumpEventQueue().then((_) =>
103 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(1 ))); 121 context.getLogs(callsTo('performAnalysisTask')).verify(happenedExactly(1 )));
104 } 122 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 @override 225 @override
208 Response handleRequest(Request request) { 226 Response handleRequest(Request request) {
209 if (request.method == 'echo') { 227 if (request.method == 'echo') {
210 var response = new Response(request.id); 228 var response = new Response(request.id);
211 response.setResult('echo', true); 229 response.setResult('echo', true);
212 return response; 230 return response;
213 } 231 }
214 return null; 232 return null;
215 } 233 }
216 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698