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

Unified Diff: pkg/analyzer/test/generated/engine_test.dart

Issue 806733003: Make futures returned by AnalysisContext cancelable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/analyzer/test/generated/engine_test.dart
diff --git a/pkg/analyzer/test/generated/engine_test.dart b/pkg/analyzer/test/generated/engine_test.dart
index 9c325f3d2cae762be868029f57eb5f25b2e4b356..2a8a6f8b8346f766b512b1a244879e07950d8314 100644
--- a/pkg/analyzer/test/generated/engine_test.dart
+++ b/pkg/analyzer/test/generated/engine_test.dart
@@ -10,6 +10,7 @@ library engine.engine_test;
import 'dart:async';
import 'dart:collection';
+import 'package:analyzer/src/cancelable_future.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/element.dart';
@@ -1152,6 +1153,34 @@ main() {}''');
});
}
+ Future test_getResolvedCompilationUnitFuture_cancel() {
+ _context = AnalysisContextFactory.contextWithCore();
+ _sourceFactory = _context.sourceFactory;
+ Source source = _addSource("/lib.dart", "library lib;");
+ // Complete all pending analysis tasks and flush the AST so that it won't
+ // be available immediately.
+ while (_context.performAnalysisTask().hasMoreWork) {}
Brian Wilkerson 2014/12/15 19:49:26 We have normally put in some limit on the number o
Paul Berry 2014/12/16 16:58:06 Done.
+ DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source);
+ dartEntry.flushAstStructures();
+ CancelableFuture<CompilationUnit> future =
+ _context.getResolvedCompilationUnitFuture(source, source);
+ bool completed = false;
+ future.then((CompilationUnit unit) {
+ fail('Future should have been canceled');
+ }, onError: (error) {
+ expect(error, new isInstanceOf<FutureCanceledError>());
+ completed = true;
+ });
+ expect(completed, isFalse);
+ expect(_context.pendingFutureSources_forTesting, isNotEmpty);
+ future.cancel();
+ expect(_context.pendingFutureSources_forTesting, isEmpty);
+ return pumpEventQueue().then((_) {
+ expect(completed, isTrue);
+ expect(_context.pendingFutureSources_forTesting, isEmpty);
+ });
+ }
+
Future test_getResolvedCompilationUnitFuture_unrelatedLibrary() {
_context = AnalysisContextFactory.contextWithCore();
_sourceFactory = _context.sourceFactory;

Powered by Google App Engine
This is Rietveld 408576698