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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1133513003: Cache flushing implementation for the task model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
11 import 'package:analyzer/src/context/cache.dart'; 11 import 'package:analyzer/src/context/cache.dart';
12 import 'package:analyzer/src/context/context.dart'; 12 import 'package:analyzer/src/context/context.dart';
13 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/element.dart'; 14 import 'package:analyzer/src/generated/element.dart';
15 import 'package:analyzer/src/generated/engine.dart' 15 import 'package:analyzer/src/generated/engine.dart'
16 show 16 show
17 AnalysisContext, 17 AnalysisContext,
18 AnalysisContextStatistics, 18 AnalysisContextStatistics,
19 AnalysisDelta, 19 AnalysisDelta,
20 AnalysisEngine, 20 AnalysisEngine,
21 AnalysisErrorInfo, 21 AnalysisErrorInfo,
22 AnalysisLevel, 22 AnalysisLevel,
23 AnalysisNotScheduledError, 23 AnalysisNotScheduledError,
24 AnalysisOptions, 24 AnalysisOptions,
25 AnalysisOptionsImpl, 25 AnalysisOptionsImpl,
26 AnalysisResult, 26 AnalysisResult,
27 CacheState,
27 ChangeNotice, 28 ChangeNotice,
28 ChangeSet, 29 ChangeSet,
29 IncrementalAnalysisCache, 30 IncrementalAnalysisCache,
30 TimestampedData; 31 TimestampedData;
31 import 'package:analyzer/src/generated/error.dart'; 32 import 'package:analyzer/src/generated/error.dart';
32 import 'package:analyzer/src/generated/html.dart' as ht; 33 import 'package:analyzer/src/generated/html.dart' as ht;
33 import 'package:analyzer/src/generated/java_engine.dart'; 34 import 'package:analyzer/src/generated/java_engine.dart';
34 import 'package:analyzer/src/generated/java_engine_io.dart'; 35 import 'package:analyzer/src/generated/java_engine_io.dart';
35 import 'package:analyzer/src/generated/resolver.dart'; 36 import 'package:analyzer/src/generated/resolver.dart';
36 import 'package:analyzer/src/generated/scanner.dart'; 37 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 expect(resolvedUnit, same(parsedUnit)); 572 expect(resolvedUnit, same(parsedUnit));
572 } 573 }
573 574
574 Future fail_computeResolvedCompilationUnitAsync_dispose() { 575 Future fail_computeResolvedCompilationUnitAsync_dispose() {
575 _context = contextWithCore(); 576 _context = contextWithCore();
576 _sourceFactory = _context.sourceFactory; 577 _sourceFactory = _context.sourceFactory;
577 Source source = _addSource("/lib.dart", "library lib;"); 578 Source source = _addSource("/lib.dart", "library lib;");
578 // Complete all pending analysis tasks and flush the AST so that it won't 579 // Complete all pending analysis tasks and flush the AST so that it won't
579 // be available immediately. 580 // be available immediately.
580 _performPendingAnalysisTasks(); 581 _performPendingAnalysisTasks();
581 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); 582 _flushAst(source);
582 entry.flushAstStructures();
583 CancelableFuture<CompilationUnit> future = 583 CancelableFuture<CompilationUnit> future =
584 _context.computeResolvedCompilationUnitAsync(source, source); 584 _context.computeResolvedCompilationUnitAsync(source, source);
585 bool completed = false; 585 bool completed = false;
586 future.then((CompilationUnit unit) { 586 future.then((CompilationUnit unit) {
587 fail('Future should have completed with error'); 587 fail('Future should have completed with error');
588 }, onError: (error) { 588 }, onError: (error) {
589 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); 589 expect(error, new isInstanceOf<AnalysisNotScheduledError>());
590 completed = true; 590 completed = true;
591 }); 591 });
592 expect(completed, isFalse); 592 expect(completed, isFalse);
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 expect(info, isNotNull); 1645 expect(info, isNotNull);
1646 } 1646 }
1647 1647
1648 Future test_computeResolvedCompilationUnitAsync_afterDispose() { 1648 Future test_computeResolvedCompilationUnitAsync_afterDispose() {
1649 _context = contextWithCore(); 1649 _context = contextWithCore();
1650 _sourceFactory = _context.sourceFactory; 1650 _sourceFactory = _context.sourceFactory;
1651 Source source = _addSource("/lib.dart", "library lib;"); 1651 Source source = _addSource("/lib.dart", "library lib;");
1652 // Complete all pending analysis tasks and flush the AST so that it won't 1652 // Complete all pending analysis tasks and flush the AST so that it won't
1653 // be available immediately. 1653 // be available immediately.
1654 _performPendingAnalysisTasks(); 1654 _performPendingAnalysisTasks();
1655 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); 1655 _flushAst(source);
1656 entry.flushAstStructures();
1657 // Dispose of the context. 1656 // Dispose of the context.
1658 _context.dispose(); 1657 _context.dispose();
1659 // Any attempt to start an asynchronous computation should return a future 1658 // Any attempt to start an asynchronous computation should return a future
1660 // which completes with error. 1659 // which completes with error.
1661 CancelableFuture<CompilationUnit> future = 1660 CancelableFuture<CompilationUnit> future =
1662 _context.computeResolvedCompilationUnitAsync(source, source); 1661 _context.computeResolvedCompilationUnitAsync(source, source);
1663 bool completed = false; 1662 bool completed = false;
1664 future.then((CompilationUnit unit) { 1663 future.then((CompilationUnit unit) {
1665 fail('Future should have completed with error'); 1664 fail('Future should have completed with error');
1666 }, onError: (error) { 1665 }, onError: (error) {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 2108
2110 void test_parseCompilationUnit_noErrors() { 2109 void test_parseCompilationUnit_noErrors() {
2111 Source source = _addSource("/lib.dart", "library lib;"); 2110 Source source = _addSource("/lib.dart", "library lib;");
2112 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); 2111 CompilationUnit compilationUnit = _context.parseCompilationUnit(source);
2113 expect(compilationUnit, isNotNull); 2112 expect(compilationUnit, isNotNull);
2114 AnalysisErrorInfo errorInfo = _context.getErrors(source); 2113 AnalysisErrorInfo errorInfo = _context.getErrors(source);
2115 expect(errorInfo, isNotNull); 2114 expect(errorInfo, isNotNull);
2116 expect(errorInfo.errors, hasLength(0)); 2115 expect(errorInfo.errors, hasLength(0));
2117 } 2116 }
2118 2117
2119 // void test_resolveCompilationUnit_sourceChangeDuringResolution() {
2120 // _context = new _AnalysisContext_sourceChangeDuringResolution();
2121 // AnalysisContextFactory.initContextWithCore(_context);
2122 // _sourceFactory = _context.sourceFactory;
2123 // Source source = _addSource("/lib.dart", "library lib;");
2124 // CompilationUnit compilationUnit =
2125 // _context.resolveCompilationUnit2(source, source);
2126 // expect(compilationUnit, isNotNull);
2127 // expect(_context.getLineInfo(source), isNotNull);
2128 // }
2129
2130 void test_parseCompilationUnit_nonExistentSource() { 2118 void test_parseCompilationUnit_nonExistentSource() {
2131 Source source = 2119 Source source =
2132 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 2120 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
2133 try { 2121 try {
2134 _context.parseCompilationUnit(source); 2122 _context.parseCompilationUnit(source);
2135 fail("Expected AnalysisException because file does not exist"); 2123 fail("Expected AnalysisException because file does not exist");
2136 } on AnalysisException { 2124 } on AnalysisException {
2137 // Expected result 2125 // Expected result
2138 } 2126 }
2139 } 2127 }
2140 2128
2129 // void test_resolveCompilationUnit_sourceChangeDuringResolution() {
2130 // _context = new _AnalysisContext_sourceChangeDuringResolution();
2131 // AnalysisContextFactory.initContextWithCore(_context);
2132 // _sourceFactory = _context.sourceFactory;
2133 // Source source = _addSource("/lib.dart", "library lib;");
2134 // CompilationUnit compilationUnit =
2135 // _context.resolveCompilationUnit2(source, source);
2136 // expect(compilationUnit, isNotNull);
2137 // expect(_context.getLineInfo(source), isNotNull);
2138 // }
2139
2141 void test_performAnalysisTask_modifiedAfterParse() { 2140 void test_performAnalysisTask_modifiedAfterParse() {
2142 // TODO(scheglov) no threads in Dart 2141 // TODO(scheglov) no threads in Dart
2143 // Source source = _addSource("/test.dart", "library lib;"); 2142 // Source source = _addSource("/test.dart", "library lib;");
2144 // int initialTime = _context.getModificationStamp(source); 2143 // int initialTime = _context.getModificationStamp(source);
2145 // List<Source> sources = new List<Source>(); 2144 // List<Source> sources = new List<Source>();
2146 // sources.add(source); 2145 // sources.add(source);
2147 // _context.analysisPriorityOrder = sources; 2146 // _context.analysisPriorityOrder = sources;
2148 // _context.parseCompilationUnit(source); 2147 // _context.parseCompilationUnit(source);
2149 // while (initialTime == JavaSystem.currentTimeMillis()) { 2148 // while (initialTime == JavaSystem.currentTimeMillis()) {
2150 // Thread.sleep(1); 2149 // Thread.sleep(1);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); 2292 expect(_context.sourcesNeedingProcessing.contains(source), isFalse);
2294 } 2293 }
2295 2294
2296 Future xtest_computeResolvedCompilationUnitAsync() { 2295 Future xtest_computeResolvedCompilationUnitAsync() {
2297 _context = contextWithCore(); 2296 _context = contextWithCore();
2298 _sourceFactory = _context.sourceFactory; 2297 _sourceFactory = _context.sourceFactory;
2299 Source source = _addSource("/lib.dart", "library lib;"); 2298 Source source = _addSource("/lib.dart", "library lib;");
2300 // Complete all pending analysis tasks and flush the AST so that it won't 2299 // Complete all pending analysis tasks and flush the AST so that it won't
2301 // be available immediately. 2300 // be available immediately.
2302 _performPendingAnalysisTasks(); 2301 _performPendingAnalysisTasks();
2303 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); 2302 _flushAst(source);
2304 entry.flushAstStructures();
2305 bool completed = false; 2303 bool completed = false;
2306 _context 2304 _context
2307 .computeResolvedCompilationUnitAsync(source, source) 2305 .computeResolvedCompilationUnitAsync(source, source)
2308 .then((CompilationUnit unit) { 2306 .then((CompilationUnit unit) {
2309 expect(unit, isNotNull); 2307 expect(unit, isNotNull);
2310 completed = true; 2308 completed = true;
2311 }); 2309 });
2312 return pumpEventQueue().then((_) { 2310 return pumpEventQueue().then((_) {
2313 expect(completed, isFalse); 2311 expect(completed, isFalse);
2314 _performPendingAnalysisTasks(); 2312 _performPendingAnalysisTasks();
2315 }).then((_) => pumpEventQueue()).then((_) { 2313 }).then((_) => pumpEventQueue()).then((_) {
2316 expect(completed, isTrue); 2314 expect(completed, isTrue);
2317 }); 2315 });
2318 } 2316 }
2319 2317
2320 Future xtest_computeResolvedCompilationUnitAsync_cancel() { 2318 Future xtest_computeResolvedCompilationUnitAsync_cancel() {
2321 _context = contextWithCore(); 2319 _context = contextWithCore();
2322 _sourceFactory = _context.sourceFactory; 2320 _sourceFactory = _context.sourceFactory;
2323 Source source = _addSource("/lib.dart", "library lib;"); 2321 Source source = _addSource("/lib.dart", "library lib;");
2324 // Complete all pending analysis tasks and flush the AST so that it won't 2322 // Complete all pending analysis tasks and flush the AST so that it won't
2325 // be available immediately. 2323 // be available immediately.
2326 _performPendingAnalysisTasks(); 2324 _performPendingAnalysisTasks();
2327 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); 2325 _flushAst(source);
2328 entry.flushAstStructures();
2329 CancelableFuture<CompilationUnit> future = 2326 CancelableFuture<CompilationUnit> future =
2330 _context.computeResolvedCompilationUnitAsync(source, source); 2327 _context.computeResolvedCompilationUnitAsync(source, source);
2331 bool completed = false; 2328 bool completed = false;
2332 future.then((CompilationUnit unit) { 2329 future.then((CompilationUnit unit) {
2333 fail('Future should have been canceled'); 2330 fail('Future should have been canceled');
2334 }, onError: (error) { 2331 }, onError: (error) {
2335 expect(error, new isInstanceOf<FutureCanceledError>()); 2332 expect(error, new isInstanceOf<FutureCanceledError>());
2336 completed = true; 2333 completed = true;
2337 }); 2334 });
2338 expect(completed, isFalse); 2335 expect(completed, isFalse);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 */ 2434 */
2438 ClassElement _findClass(CompilationUnitElement unit, String className) { 2435 ClassElement _findClass(CompilationUnitElement unit, String className) {
2439 for (ClassElement classElement in unit.types) { 2436 for (ClassElement classElement in unit.types) {
2440 if (classElement.displayName == className) { 2437 if (classElement.displayName == className) {
2441 return classElement; 2438 return classElement;
2442 } 2439 }
2443 } 2440 }
2444 return null; 2441 return null;
2445 } 2442 }
2446 2443
2444 void _flushAst(Source source) {
2445 CacheEntry entry = _context.getReadableSourceEntryOrNull(source);
2446 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED);
2447 }
2448
2447 IncrementalAnalysisCache _getIncrementalAnalysisCache( 2449 IncrementalAnalysisCache _getIncrementalAnalysisCache(
2448 AnalysisContextImpl context2) { 2450 AnalysisContextImpl context2) {
2449 return context2.test_incrementalAnalysisCache; 2451 return context2.test_incrementalAnalysisCache;
2450 } 2452 }
2451 2453
2452 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { 2454 List<Source> _getPriorityOrder(AnalysisContextImpl context2) {
2453 return context2.test_priorityOrder; 2455 return context2.test_priorityOrder;
2454 } 2456 }
2455 2457
2456 void _performPendingAnalysisTasks([int maxTasks = 20]) { 2458 void _performPendingAnalysisTasks([int maxTasks = 20]) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 : super(name, UriKind.FILE_URI); 2527 : super(name, UriKind.FILE_URI);
2526 2528
2527 @override 2529 @override
2528 TimestampedData<String> get contents { 2530 TimestampedData<String> get contents {
2529 throw 'Read error'; 2531 throw 'Read error';
2530 } 2532 }
2531 2533
2532 @override 2534 @override
2533 bool exists() => true; 2535 bool exists() => true;
2534 } 2536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698