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

Side by Side Diff: tests/standalone/io/code_collection_test.dart

Issue 1948353004: - Harden code_collection_test against GCs happening at unexpected (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 | « no previous file | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Dart test program testing code GC. 5 // Dart test program testing code GC.
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "dart:async"; 8 import "dart:async";
9 import "dart:io"; 9 import "dart:io";
10 10
11 11
12 int foo(int x) { 12 int foo(int x) {
13 x = x + 1; 13 x = x + 1;
14 print("foo=$x");
14 return x; 15 return x;
15 } 16 }
16 17
17 18
18 List<int> bar() { 19 List<int> bar() {
19 // A couple of big allocations trigger GC. 20 // A couple of big allocations trigger GC.
20 var l = new List.filled(700000, 7); 21 var l = new List.filled(700000, 7);
21 return l; 22 return l;
22 } 23 }
23 24
24 25
25 doTest() { 26 doTest() {
26 var i = 0; 27 var i = 0;
27 var ret = foo(1); // Initial call to compile. 28 var ret = foo(1); // Initial call to compile.
28 print("foo=$ret");
29 // Time passes, GC runs, foo's code is dropped. 29 // Time passes, GC runs, foo's code is dropped.
30 var ms = const Duration(milliseconds: 100); 30 var ms = const Duration(milliseconds: 100);
31 var t = new Timer.periodic(ms, (timer) { 31 var t = new Timer.periodic(ms, (timer) {
32 i++; 32 i++;
33 // Calling bar will trigger GC without foo being on the stack. This way
34 // the method can be collected.
33 bar(); 35 bar();
34 if (i > 1) { 36 if (i > 1) {
35 timer.cancel(); 37 timer.cancel();
36 // foo is called again to make sure we can still run it even after 38 // foo is called again to make sure we can still run it even after
37 // its code has been detached. 39 // its code has been detached.
38 var ret = foo(2); 40 var ret = foo(2);
39 print("foo=$ret");
40 } 41 }
41 }); 42 });
42 } 43 }
43 44
44 45
45 main(List<String> arguments) { 46 main(List<String> arguments) {
46 if (arguments.contains("--run")) { 47 if (arguments.contains("--run")) {
47 doTest(); 48 doTest();
48 } else { 49 } else {
49 // Run the test and capture stdout. 50 // Run the test and capture stdout.
(...skipping 24 matching lines...) Expand all
74 count++; 75 count++;
75 } 76 }
76 if (line.contains("foo=3")) { 77 if (line.contains("foo=3")) {
77 Expect.equals(2, count); 78 Expect.equals(2, count);
78 count++; 79 count++;
79 } 80 }
80 }); 81 });
81 Expect.equals(3, count); 82 Expect.equals(3, count);
82 } 83 }
83 } 84 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698