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

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

Issue 1154563002: Fix for a memory leak in CacheFlushManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
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
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.driver_test; 5 library test.src.task.driver_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/engine.dart' 8 import 'package:analyzer/src/generated/engine.dart'
9 show 9 show
10 AnalysisContext, 10 AnalysisContext,
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 manager.resultStored(result1, null); 682 manager.resultStored(result1, null);
683 manager.resultStored(result2, null); 683 manager.resultStored(result2, null);
684 expect(manager.currentSize, 2); 684 expect(manager.currentSize, 2);
685 expect(manager.recentlyUsed, orderedEquals([result1, result2])); 685 expect(manager.recentlyUsed, orderedEquals([result1, result2]));
686 // access result3, no-op 686 // access result3, no-op
687 manager.resultAccessed(result3); 687 manager.resultAccessed(result3);
688 expect(manager.currentSize, 2); 688 expect(manager.currentSize, 2);
689 expect(manager.recentlyUsed, orderedEquals([result1, result2])); 689 expect(manager.recentlyUsed, orderedEquals([result1, result2]));
690 } 690 }
691 691
692 test_resultAccessed_unlimitedCachingPolicy() {
693 manager = new CacheFlushManager(new SimpleResultCachingPolicy(-1, -1),
694 (AnalysisTarget target) => false);
695 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null);
696 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null);
697 AnalysisTarget target = new TestSource();
698 TargetedResult result1 = new TargetedResult(target, descriptor1);
699 TargetedResult result2 = new TargetedResult(target, descriptor2);
700 manager.resultStored(result1, null);
701 manager.resultStored(result2, null);
702 expect(manager.currentSize, 0);
703 expect(manager.recentlyUsed, isEmpty);
704 // access result2
705 manager.resultAccessed(result2);
706 expect(manager.currentSize, 0);
707 expect(manager.recentlyUsed, isEmpty);
708 }
709
692 test_resultStored() { 710 test_resultStored() {
693 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); 711 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null);
694 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); 712 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null);
695 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); 713 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null);
696 ResultDescriptor descriptor4 = new ResultDescriptor('result4', null); 714 ResultDescriptor descriptor4 = new ResultDescriptor('result4', null);
697 AnalysisTarget target = new TestSource(); 715 AnalysisTarget target = new TestSource();
698 TargetedResult result1 = new TargetedResult(target, descriptor1); 716 TargetedResult result1 = new TargetedResult(target, descriptor1);
699 TargetedResult result2 = new TargetedResult(target, descriptor2); 717 TargetedResult result2 = new TargetedResult(target, descriptor2);
700 TargetedResult result3 = new TargetedResult(target, descriptor3); 718 TargetedResult result3 = new TargetedResult(target, descriptor3);
701 TargetedResult result4 = new TargetedResult(target, descriptor4); 719 TargetedResult result4 = new TargetedResult(target, descriptor4);
(...skipping 12 matching lines...) Expand all
714 // store result4 732 // store result4
715 { 733 {
716 List<TargetedResult> resultsToFlush = manager.resultStored(result4, null); 734 List<TargetedResult> resultsToFlush = manager.resultStored(result4, null);
717 expect(resultsToFlush, [result1]); 735 expect(resultsToFlush, [result1]);
718 expect(manager.currentSize, 3); 736 expect(manager.currentSize, 3);
719 expect(manager.recentlyUsed, orderedEquals([result3, result2, result4])); 737 expect(manager.recentlyUsed, orderedEquals([result3, result2, result4]));
720 expect(manager.resultSizeMap, {result3: 1, result2: 1, result4: 1}); 738 expect(manager.resultSizeMap, {result3: 1, result2: 1, result4: 1});
721 } 739 }
722 } 740 }
723 741
742 test_resultStored_unlimitedCachingPolicy() {
743 manager = new CacheFlushManager(new SimpleResultCachingPolicy(-1, -1),
744 (AnalysisTarget target) => false);
745 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null);
746 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null);
747 AnalysisTarget target = new TestSource();
748 TargetedResult result1 = new TargetedResult(target, descriptor1);
749 TargetedResult result2 = new TargetedResult(target, descriptor2);
750 manager.resultStored(result1, null);
751 manager.resultStored(result2, null);
752 expect(manager.currentSize, 0);
753 expect(manager.recentlyUsed, isEmpty);
754 }
755
724 test_targetRemoved() { 756 test_targetRemoved() {
725 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null); 757 ResultDescriptor descriptor1 = new ResultDescriptor('result1', null);
726 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null); 758 ResultDescriptor descriptor2 = new ResultDescriptor('result2', null);
727 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null); 759 ResultDescriptor descriptor3 = new ResultDescriptor('result3', null);
728 AnalysisTarget target1 = new TestSource('a.dart'); 760 AnalysisTarget target1 = new TestSource('a.dart');
729 AnalysisTarget target2 = new TestSource('b.dart'); 761 AnalysisTarget target2 = new TestSource('b.dart');
730 TargetedResult result1 = new TargetedResult(target1, descriptor1); 762 TargetedResult result1 = new TargetedResult(target1, descriptor1);
731 TargetedResult result2 = new TargetedResult(target2, descriptor2); 763 TargetedResult result2 = new TargetedResult(target2, descriptor2);
732 TargetedResult result3 = new TargetedResult(target1, descriptor3); 764 TargetedResult result3 = new TargetedResult(target1, descriptor3);
733 manager.resultStored(result1, null); 765 manager.resultStored(result1, null);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 895
864 class _InternalAnalysisContextMock extends TypedMock 896 class _InternalAnalysisContextMock extends TypedMock
865 implements InternalAnalysisContext { 897 implements InternalAnalysisContext {
866 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 898 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
867 } 899 }
868 900
869 class _TestAnalysisTarget implements AnalysisTarget { 901 class _TestAnalysisTarget implements AnalysisTarget {
870 @override 902 @override
871 Source get source => null; 903 Source get source => null;
872 } 904 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698