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

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

Issue 875163002: Make AnalysisServer.onAnalysisComplete a Future and wait for it before refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use Completer instead of busy loop Created 5 years, 10 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 mocks; 5 library mocks;
6 6
7 @MirrorsUsed(targets: 'mocks', override: '*') 7 @MirrorsUsed(targets: 'mocks', override: '*')
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 */ 60 */
61 Future pumpEventQueue([int times = 50]) { 61 Future pumpEventQueue([int times = 50]) {
62 if (times == 0) return new Future.value(); 62 if (times == 0) return new Future.value();
63 // We use a delayed future to allow microtask events to finish. The 63 // We use a delayed future to allow microtask events to finish. The
64 // Future.value or Future() constructors use scheduleMicrotask themselves and 64 // Future.value or Future() constructors use scheduleMicrotask themselves and
65 // would therefore not wait for microtask callbacks that are scheduled after 65 // would therefore not wait for microtask callbacks that are scheduled after
66 // invoking this method. 66 // invoking this method.
67 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); 67 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1));
68 } 68 }
69 69
70 /**
71 * Returns a [Future] that completes when the given [AnalysisServer] finished
72 * all its scheduled tasks.
73 */
74 Future waitForServerOperationsPerformed(AnalysisServer server) {
75 if (server.isAnalysisComplete()) {
76 return new Future.value();
77 }
78 // We use a delayed future to allow microtask events to finish. The
79 // Future.value or Future() constructors use scheduleMicrotask themselves and
80 // would therefore not wait for microtask callbacks that are scheduled after
81 // invoking this method.
82 return new Future.delayed(
83 Duration.ZERO,
84 () => waitForServerOperationsPerformed(server));
85 }
86
87 typedef void MockServerOperationPerformFunction(AnalysisServer server); 70 typedef void MockServerOperationPerformFunction(AnalysisServer server);
88 71
89 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { 72 class MockAnalysisContext extends StringTypedMock implements AnalysisContext {
90 MockAnalysisContext(String name) : super(name); 73 MockAnalysisContext(String name) : super(name);
91 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 74 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
92 } 75 }
93 76
94 class MockClassElement extends TypedMock implements ClassElement { 77 class MockClassElement extends TypedMock implements ClassElement {
95 final ElementKind kind = ElementKind.CLASS; 78 final ElementKind kind = ElementKind.CLASS;
96 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 79 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 481 }
499 return mismatchDescription; 482 return mismatchDescription;
500 } 483 }
501 484
502 @override 485 @override
503 bool matches(item, Map matchState) { 486 bool matches(item, Map matchState) {
504 Response response = item; 487 Response response = item;
505 return response != null && response.id == _id && response.error == null; 488 return response != null && response.id == _id && response.error == null;
506 } 489 }
507 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698