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

Side by Side 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 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.engine_test; 8 library engine.engine_test;
9 9
10 import 'dart:async'; 10 import 'dart:async';
11 import 'dart:collection'; 11 import 'dart:collection';
12 12
13 import 'package:analyzer/src/cancelable_future.dart';
13 import 'package:analyzer/src/generated/ast.dart'; 14 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/constant.dart'; 15 import 'package:analyzer/src/generated/constant.dart';
15 import 'package:analyzer/src/generated/element.dart'; 16 import 'package:analyzer/src/generated/element.dart';
16 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
17 import 'package:analyzer/src/generated/error.dart'; 18 import 'package:analyzer/src/generated/error.dart';
18 import 'package:analyzer/src/generated/html.dart' as ht; 19 import 'package:analyzer/src/generated/html.dart' as ht;
19 import 'package:analyzer/src/generated/java_core.dart'; 20 import 'package:analyzer/src/generated/java_core.dart';
20 import 'package:analyzer/src/generated/java_engine.dart'; 21 import 'package:analyzer/src/generated/java_engine.dart';
21 import 'package:analyzer/src/generated/java_engine_io.dart'; 22 import 'package:analyzer/src/generated/java_engine_io.dart';
22 import 'package:analyzer/src/generated/parser.dart'; 23 import 'package:analyzer/src/generated/parser.dart';
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 completed = true; 1146 completed = true;
1146 }); 1147 });
1147 return pumpEventQueue().then((_) { 1148 return pumpEventQueue().then((_) {
1148 expect(completed, isFalse); 1149 expect(completed, isFalse);
1149 while (_context.performAnalysisTask().hasMoreWork) {} 1150 while (_context.performAnalysisTask().hasMoreWork) {}
1150 }).then((_) => pumpEventQueue()).then((_) { 1151 }).then((_) => pumpEventQueue()).then((_) {
1151 expect(completed, isTrue); 1152 expect(completed, isTrue);
1152 }); 1153 });
1153 } 1154 }
1154 1155
1156 Future test_getResolvedCompilationUnitFuture_cancel() {
1157 _context = AnalysisContextFactory.contextWithCore();
1158 _sourceFactory = _context.sourceFactory;
1159 Source source = _addSource("/lib.dart", "library lib;");
1160 // Complete all pending analysis tasks and flush the AST so that it won't
1161 // be available immediately.
1162 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.
1163 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source);
1164 dartEntry.flushAstStructures();
1165 CancelableFuture<CompilationUnit> future =
1166 _context.getResolvedCompilationUnitFuture(source, source);
1167 bool completed = false;
1168 future.then((CompilationUnit unit) {
1169 fail('Future should have been canceled');
1170 }, onError: (error) {
1171 expect(error, new isInstanceOf<FutureCanceledError>());
1172 completed = true;
1173 });
1174 expect(completed, isFalse);
1175 expect(_context.pendingFutureSources_forTesting, isNotEmpty);
1176 future.cancel();
1177 expect(_context.pendingFutureSources_forTesting, isEmpty);
1178 return pumpEventQueue().then((_) {
1179 expect(completed, isTrue);
1180 expect(_context.pendingFutureSources_forTesting, isEmpty);
1181 });
1182 }
1183
1155 Future test_getResolvedCompilationUnitFuture_unrelatedLibrary() { 1184 Future test_getResolvedCompilationUnitFuture_unrelatedLibrary() {
1156 _context = AnalysisContextFactory.contextWithCore(); 1185 _context = AnalysisContextFactory.contextWithCore();
1157 _sourceFactory = _context.sourceFactory; 1186 _sourceFactory = _context.sourceFactory;
1158 Source librarySource = _addSource("/lib.dart", "library lib;"); 1187 Source librarySource = _addSource("/lib.dart", "library lib;");
1159 Source partSource = _addSource("/part.dart", "part of foo;"); 1188 Source partSource = _addSource("/part.dart", "part of foo;");
1160 bool completed = false; 1189 bool completed = false;
1161 _context.getResolvedCompilationUnitFuture( 1190 _context.getResolvedCompilationUnitFuture(
1162 partSource, 1191 partSource,
1163 librarySource).then((_) { 1192 librarySource).then((_) {
1164 fail('Expected resolution to fail'); 1193 fail('Expected resolution to fail');
(...skipping 5889 matching lines...) Expand 10 before | Expand all | Expand 10 after
7054 bool contains(Source source) => source == libB; 7083 bool contains(Source source) => source == libB;
7055 } 7084 }
7056 7085
7057 7086
7058 class _UniversalCachePartitionTest_test_setMaxCacheSize implements 7087 class _UniversalCachePartitionTest_test_setMaxCacheSize implements
7059 CacheRetentionPolicy { 7088 CacheRetentionPolicy {
7060 @override 7089 @override
7061 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => 7090 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) =>
7062 RetentionPriority.LOW; 7091 RetentionPriority.LOW;
7063 } 7092 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698