OLD | NEW |
---|---|
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 // Windows doesn't support sending signals. | 5 // Windows doesn't support sending signals. |
6 @TestOn("vm && !windows") | 6 @TestOn("vm && !windows") |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
kevmoo
2015/06/17 22:20:04
unused
nweiz
2015/06/17 22:41:08
Done.
| |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import 'package:path/path.dart' as p; | 12 import 'package:path/path.dart' as p; |
13 import 'package:test/src/util/io.dart'; | |
14 import 'package:test/src/utils.dart'; | |
13 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
14 import 'package:test/src/util/io.dart'; | |
15 | 16 |
16 import '../io.dart'; | 17 import '../io.dart'; |
17 | 18 |
18 String _sandbox; | 19 String _sandbox; |
19 | 20 |
20 String get _tempDir => p.join(_sandbox, "tmp"); | 21 String get _tempDir => p.join(_sandbox, "tmp"); |
21 | 22 |
22 final _lines = UTF8.decoder.fuse(const LineSplitter()); | |
23 | |
24 // This test is inherently prone to race conditions. If it fails, it will likely | 23 // This test is inherently prone to race conditions. If it fails, it will likely |
25 // do so flakily, but if it succeeds, it will succeed consistently. The tests | 24 // do so flakily, but if it succeeds, it will succeed consistently. The tests |
26 // represent a best effort to kill the test runner at certain times during its | 25 // represent a best effort to kill the test runner at certain times during its |
27 // execution. | 26 // execution. |
28 void main() { | 27 void main() { |
29 setUp(() { | 28 setUp(() { |
30 _sandbox = createTempDir(); | 29 _sandbox = createTempDir(); |
31 }); | 30 }); |
32 | 31 |
33 tearDown(() { | 32 tearDown(() { |
34 new Directory(_sandbox).deleteSync(recursive: true); | 33 new Directory(_sandbox).deleteSync(recursive: true); |
35 }); | 34 }); |
36 | 35 |
37 group("during loading,", () { | 36 group("during loading,", () { |
38 test("cleans up if killed while loading a VM test", () async { | 37 test("cleans up if killed while loading a VM test", () async { |
39 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 38 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
40 void main() { | 39 void main() { |
41 print("in test.dart"); | 40 print("in test.dart"); |
42 // Spin for a long time so the test is probably killed while still loading. | 41 // Spin for a long time so the test is probably killed while still loading. |
43 for (var i = 0; i < 100000000; i++) {} | 42 for (var i = 0; i < 100000000; i++) {} |
44 } | 43 } |
45 """); | 44 """); |
46 | 45 |
47 var process = await _startTest(["test.dart"]); | 46 var process = await _startTest(["test.dart"]); |
48 var line = await _lines.bind(process.stdout).first; | 47 var line = await lineSplitter.bind(process.stdout).first; |
49 expect(line, equals("in test.dart")); | 48 expect(line, equals("in test.dart")); |
50 process.kill(); | 49 process.kill(); |
51 await process.exitCode; | 50 await process.exitCode; |
52 expect(new Directory(_tempDir).listSync(), isEmpty); | 51 expect(new Directory(_tempDir).listSync(), isEmpty); |
53 }); | 52 }); |
54 | 53 |
55 test("cleans up if killed while loading a browser test", () async { | 54 test("cleans up if killed while loading a browser test", () async { |
56 new File(p.join(_sandbox, "test.dart")) | 55 new File(p.join(_sandbox, "test.dart")) |
57 .writeAsStringSync("void main() {}"); | 56 .writeAsStringSync("void main() {}"); |
58 | 57 |
59 var process = await _startTest(["-p", "chrome", "test.dart"]); | 58 var process = await _startTest(["-p", "chrome", "test.dart"]); |
60 var line = await _lines.bind(process.stdout).first; | 59 var line = await lineSplitter.bind(process.stdout).first; |
61 expect(line, equals("Compiling test.dart...")); | 60 expect(line, equals("Compiling test.dart...")); |
62 process.kill(); | 61 process.kill(); |
63 await process.exitCode; | 62 await process.exitCode; |
64 expect(new Directory(_tempDir).listSync(), isEmpty); | 63 expect(new Directory(_tempDir).listSync(), isEmpty); |
65 }); | 64 }); |
66 | 65 |
67 test("exits immediately if ^C is sent twice", () async { | 66 test("exits immediately if ^C is sent twice", () async { |
68 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 67 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
69 void main() { | 68 void main() { |
70 print("in test.dart"); | 69 print("in test.dart"); |
71 while (true) {} | 70 while (true) {} |
72 } | 71 } |
73 """); | 72 """); |
74 | 73 |
75 var process = await _startTest(["test.dart"]); | 74 var process = await _startTest(["test.dart"]); |
76 var line = await _lines.bind(process.stdout).first; | 75 var line = await lineSplitter.bind(process.stdout).first; |
77 expect(line, equals("in test.dart")); | 76 expect(line, equals("in test.dart")); |
78 process.kill(); | 77 process.kill(); |
79 | 78 |
80 // TODO(nweiz): Sending two signals in close succession can cause the | 79 // TODO(nweiz): Sending two signals in close succession can cause the |
81 // second one to be ignored, so we wait a bit before the second | 80 // second one to be ignored, so we wait a bit before the second |
82 // one. Remove this hack when issue 23047 is fixed. | 81 // one. Remove this hack when issue 23047 is fixed. |
83 await new Future.delayed(new Duration(seconds: 1)); | 82 await new Future.delayed(new Duration(seconds: 1)); |
84 process.kill(); | 83 process.kill(); |
85 await process.exitCode; | 84 await process.exitCode; |
86 expect(new Directory(_tempDir).listSync(), isEmpty); | 85 expect(new Directory(_tempDir).listSync(), isEmpty); |
(...skipping 12 matching lines...) Expand all Loading... | |
99 tearDown(() => new File("output").writeAsStringSync("ran teardown")); | 98 tearDown(() => new File("output").writeAsStringSync("ran teardown")); |
100 | 99 |
101 test("test", () { | 100 test("test", () { |
102 print("running test"); | 101 print("running test"); |
103 return new Future.delayed(new Duration(seconds: 1)); | 102 return new Future.delayed(new Duration(seconds: 1)); |
104 }); | 103 }); |
105 } | 104 } |
106 """); | 105 """); |
107 | 106 |
108 var process = await _startTest(["test.dart"]); | 107 var process = await _startTest(["test.dart"]); |
109 var line = await _lines.bind(process.stdout).skip(2).first; | 108 var line = await lineSplitter.bind(process.stdout).skip(2).first; |
110 expect(line, equals("running test")); | 109 expect(line, equals("running test")); |
111 process.kill(); | 110 process.kill(); |
112 await process.exitCode; | 111 await process.exitCode; |
113 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), | 112 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), |
114 equals("ran teardown")); | 113 equals("ran teardown")); |
115 expect(new Directory(_tempDir).listSync(), isEmpty); | 114 expect(new Directory(_tempDir).listSync(), isEmpty); |
116 }); | 115 }); |
117 | 116 |
118 test("kills a browser test immediately", () async { | 117 test("kills a browser test immediately", () async { |
119 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 118 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
(...skipping 11 matching lines...) Expand all Loading... | |
131 // stops. | 130 // stops. |
132 while (true) {} | 131 while (true) {} |
133 }); | 132 }); |
134 }); | 133 }); |
135 } | 134 } |
136 """); | 135 """); |
137 | 136 |
138 var process = await _startTest(["-p", "content-shell", "test.dart"]); | 137 var process = await _startTest(["-p", "content-shell", "test.dart"]); |
139 // The first line is blank, and the second is a status line from the | 138 // The first line is blank, and the second is a status line from the |
140 // reporter. | 139 // reporter. |
141 var line = await _lines.bind(process.stdout).skip(2).first; | 140 var line = await lineSplitter.bind(process.stdout).skip(2).first; |
142 expect(line, equals("running test")); | 141 expect(line, equals("running test")); |
143 process.kill(); | 142 process.kill(); |
144 await process.exitCode; | 143 await process.exitCode; |
145 expect(new Directory(_tempDir).listSync(), isEmpty); | 144 expect(new Directory(_tempDir).listSync(), isEmpty); |
146 }); | 145 }); |
147 | 146 |
148 test("kills a VM test immediately if ^C is sent twice", () async { | 147 test("kills a VM test immediately if ^C is sent twice", () async { |
149 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 148 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
150 import 'package:test/test.dart'; | 149 import 'package:test/test.dart'; |
151 | 150 |
152 void main() { | 151 void main() { |
153 test("test", () { | 152 test("test", () { |
154 print("running test"); | 153 print("running test"); |
155 while (true) {} | 154 while (true) {} |
156 }); | 155 }); |
157 } | 156 } |
158 """); | 157 """); |
159 | 158 |
160 var process = await _startTest(["test.dart"]); | 159 var process = await _startTest(["test.dart"]); |
161 var line = await _lines.bind(process.stdout).skip(2).first; | 160 var line = await lineSplitter.bind(process.stdout).skip(2).first; |
162 expect(line, equals("running test")); | 161 expect(line, equals("running test")); |
163 process.kill(); | 162 process.kill(); |
164 | 163 |
165 // TODO(nweiz): Sending two signals in close succession can cause the | 164 // TODO(nweiz): Sending two signals in close succession can cause the |
166 // second one to be ignored, so we wait a bit before the second | 165 // second one to be ignored, so we wait a bit before the second |
167 // one. Remove this hack when issue 23047 is fixed. | 166 // one. Remove this hack when issue 23047 is fixed. |
168 await new Future.delayed(new Duration(seconds: 1)); | 167 await new Future.delayed(new Duration(seconds: 1)); |
169 process.kill(); | 168 process.kill(); |
170 await process.exitCode; | 169 await process.exitCode; |
171 }); | 170 }); |
(...skipping 19 matching lines...) Expand all Loading... | |
191 try { | 190 try { |
192 expect(true, isTrue); | 191 expect(true, isTrue); |
193 } catch (_) { | 192 } catch (_) { |
194 expectThrewError = true; | 193 expectThrewError = true; |
195 } | 194 } |
196 }); | 195 }); |
197 } | 196 } |
198 """); | 197 """); |
199 | 198 |
200 var process = await _startTest(["test.dart"]); | 199 var process = await _startTest(["test.dart"]); |
201 var line = await _lines.bind(process.stdout).skip(2).first; | 200 var line = await lineSplitter.bind(process.stdout).skip(2).first; |
202 expect(line, equals("running test")); | 201 expect(line, equals("running test")); |
203 process.kill(); | 202 process.kill(); |
204 await process.exitCode; | 203 await process.exitCode; |
205 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), | 204 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), |
206 equals("true")); | 205 equals("true")); |
207 expect(new Directory(_tempDir).listSync(), isEmpty); | 206 expect(new Directory(_tempDir).listSync(), isEmpty); |
208 }); | 207 }); |
209 | 208 |
210 test("causes expectAsync() to always throw an error immediately", () async { | 209 test("causes expectAsync() to always throw an error immediately", () async { |
211 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 210 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
(...skipping 16 matching lines...) Expand all Loading... | |
228 try { | 227 try { |
229 expectAsync(() {}); | 228 expectAsync(() {}); |
230 } catch (_) { | 229 } catch (_) { |
231 expectAsyncThrewError = true; | 230 expectAsyncThrewError = true; |
232 } | 231 } |
233 }); | 232 }); |
234 } | 233 } |
235 """); | 234 """); |
236 | 235 |
237 var process = await _startTest(["test.dart"]); | 236 var process = await _startTest(["test.dart"]); |
238 var line = await _lines.bind(process.stdout).skip(2).first; | 237 var line = await lineSplitter.bind(process.stdout).skip(2).first; |
239 expect(line, equals("running test")); | 238 expect(line, equals("running test")); |
240 process.kill(); | 239 process.kill(); |
241 await process.exitCode; | 240 await process.exitCode; |
242 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), | 241 expect(new File(p.join(_sandbox, "output")).readAsStringSync(), |
243 equals("true")); | 242 equals("true")); |
244 expect(new Directory(_tempDir).listSync(), isEmpty); | 243 expect(new Directory(_tempDir).listSync(), isEmpty); |
245 }); | 244 }); |
246 }); | 245 }); |
247 } | 246 } |
248 | 247 |
249 Future<Process> _startTest(List<String> args) { | 248 Future<Process> _startTest(List<String> args) { |
250 new Directory(_tempDir).create(); | 249 new Directory(_tempDir).create(); |
251 return startTest(args, workingDirectory: _sandbox, | 250 return startTest(args, workingDirectory: _sandbox, |
252 environment: {"_UNITTEST_TEMP_DIR": _tempDir}); | 251 environment: {"_UNITTEST_TEMP_DIR": _tempDir}); |
253 } | 252 } |
OLD | NEW |