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

Side by Side Diff: pkg/scheduled_test/test/scheduled_process_test.dart

Issue 12741004: Accommodate a race condition in pkg/scheduled_test/scheduled_process_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove a bad timeout Created 7 years, 9 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
« no previous file with comments | « pkg/scheduled_test/lib/src/utils.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) 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 library scheduled_process_test; 5 library scheduled_process_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:pathos/path.dart' as path; 10 import 'package:pathos/path.dart' as path;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 }); 111 });
112 112
113 expectTestsPass("shouldExit can't be called after kill", () { 113 expectTestsPass("shouldExit can't be called after kill", () {
114 test('test', () { 114 test('test', () {
115 var process = startDartProcess(''); 115 var process = startDartProcess('');
116 process.kill(); 116 process.kill();
117 expect(() => process.shouldExit(0), throwsA(isStateError)); 117 expect(() => process.shouldExit(0), throwsA(isStateError));
118 }); 118 });
119 }); 119 });
120 120
121 // TODO(nweiz): re-enable this (issue 9022). 121 expectTestsPass("a process that ends while waiting for stdout shouldn't "
122 // expectTestsPass("a process that ends while waiting for stdout shouldn't " 122 "block the test", () {
123 // "block the test", () { 123 var errors;
124 // var errors; 124 test('test 1', () {
125 // test('test 1', () { 125 currentSchedule.onException.schedule(() {
126 // currentSchedule.onException.schedule(() { 126 errors = currentSchedule.errors;
127 // errors = currentSchedule.errors; 127 });
128 // }); 128
129 // 129 var process = startDartProcess('');
130 // var process = startDartProcess(''); 130 expect(process.nextLine(), completion(equals('hello')));
131 // expect(process.nextLine(), completion(equals('hello'))); 131 expect(process.nextLine(), completion(equals('world')));
132 // expect(process.nextLine(), completion(equals('world'))); 132 process.shouldExit(0);
133 // process.shouldExit(0); 133 });
134 // }); 134
135 // 135 test('test 2', () {
136 // test('test 2', () { 136 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
137 // expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 137 expect(errors.length, anyOf(1, 2));
138 // expect(errors.length, equals(2)); 138 expect(errors[0].error, isStateError);
139 // expect(errors[0].error, isStateError); 139 expect(errors[0].error.message, equals("No elements"));
140 // expect(errors[0].error.message, equals("No elements")); 140
141 // expect(errors[1].error, matches(r"^Process " 141 // Whether or not this error appears depends on how quickly the "no
142 // r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " 142 // elements" error is handled.
143 // r"exit code 0\.")); 143 if (errors.length == 2) {
144 // }); 144 expect(errors[1].error, matches(r"^Process "
145 // }, passing: ['test 2']); 145 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with "
146 r"exit code 0\."));
147 }
148 });
149 }, passing: ['test 2']);
146 150
147 expectTestsPass("a process that ends during the task immediately before it's " 151 expectTestsPass("a process that ends during the task immediately before it's "
148 "scheduled to end shouldn't cause an error", () { 152 "scheduled to end shouldn't cause an error", () {
149 test('test', () { 153 test('test', () {
150 var process = startDartProcess('stdin.toList();'); 154 var process = startDartProcess('stdin.toList();');
151 process.closeStdin(); 155 process.closeStdin();
152 // Unfortunately, sleeping for a second seems like the best way of 156 // Unfortunately, sleeping for a second seems like the best way of
153 // guaranteeing that the process ends during this task. 157 // guaranteeing that the process ends during this task.
154 schedule(() => new Future.delayed(new Duration(seconds: 1))); 158 schedule(() => new Future.delayed(new Duration(seconds: 1)));
155 process.shouldExit(0); 159 process.shouldExit(0);
156 }); 160 });
157 }); 161 });
158 162
159 expectTestsPass("nextLine returns the next line of stdout from the process", 163 expectTestsPass("nextLine returns the next line of stdout from the process",
160 () { 164 () {
161 test('test', () { 165 test('test', () {
162 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");'); 166 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");');
163 expect(process.nextLine(), completion(equals('hello'))); 167 expect(process.nextLine(), completion(equals('hello')));
164 expect(process.nextLine(), completion(equals(''))); 168 expect(process.nextLine(), completion(equals('')));
165 expect(process.nextLine(), completion(equals('world'))); 169 expect(process.nextLine(), completion(equals('world')));
166 expect(process.nextLine(), completion(equals('hi'))); 170 expect(process.nextLine(), completion(equals('hi')));
167 process.shouldExit(0); 171 process.shouldExit(0);
168 }); 172 });
169 }); 173 });
170 174
171 // TODO(nweiz): re-enable this (issue 9022). 175 expectTestsPass("nextLine throws an error if there's no more stdout", () {
172 // expectTestsPass("nextLine throws an error if there's no more stdout", () { 176 var errors;
173 // var errors; 177 test('test 1', () {
174 // test('test 1', () { 178 currentSchedule.onException.schedule(() {
175 // currentSchedule.onException.schedule(() { 179 errors = currentSchedule.errors;
176 // errors = currentSchedule.errors; 180 });
177 // }); 181
178 // 182 var process = startDartProcess('print("hello");');
179 // var process = startDartProcess('print("hello");'); 183 expect(process.nextLine(), completion(equals('hello')));
180 // expect(process.nextLine(), completion(equals('hello'))); 184 expect(process.nextLine(), completion(equals('world')));
181 // expect(process.nextLine(), completion(equals('world'))); 185 process.shouldExit(0);
182 // process.shouldExit(0); 186 });
183 // }); 187
184 // 188 test('test 2', () {
185 // test('test 2', () { 189 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
186 // expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 190 expect(errors.length, anyOf(1, 2));
187 // expect(errors.length, equals(2)); 191 expect(errors[0].error, isStateError);
188 // expect(errors[0].error, isStateError); 192 expect(errors[0].error.message, equals("No elements"));
189 // expect(errors[0].error.message, equals("No elements")); 193
190 // expect(errors[1].error, matches(r"^Process " 194 // Whether or not this error appears depends on how quickly the "no
191 // r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " 195 // elements" error is handled.
192 // r"exit code 0\.")); 196 if (errors.length == 2) {
193 // }); 197 expect(errors[1].error, matches(r"^Process "
194 // }, passing: ['test 2']); 198 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with "
199 r"exit code 0\."));
200 }
201 });
202 }, passing: ['test 2']);
195 203
196 expectTestsPass("nextErrLine returns the next line of stderr from the " 204 expectTestsPass("nextErrLine returns the next line of stderr from the "
197 "process", () { 205 "process", () {
198 test('test', () { 206 test('test', () {
199 var process = startDartProcess(r''' 207 var process = startDartProcess(r'''
200 stderr.write("hello\n\nworld\n"); 208 stderr.write("hello\n\nworld\n");
201 stderr.write("hi"); 209 stderr.write("hi");
202 '''); 210 ''');
203 expect(process.nextErrLine(), completion(equals('hello'))); 211 expect(process.nextErrLine(), completion(equals('hello')));
204 expect(process.nextErrLine(), completion(equals(''))); 212 expect(process.nextErrLine(), completion(equals('')));
205 expect(process.nextErrLine(), completion(equals('world'))); 213 expect(process.nextErrLine(), completion(equals('world')));
206 expect(process.nextErrLine(), completion(equals('hi'))); 214 expect(process.nextErrLine(), completion(equals('hi')));
207 process.shouldExit(0); 215 process.shouldExit(0);
208 }); 216 });
209 }); 217 });
210 218
211 // TODO(nweiz): re-enable this (issue 9022). 219 expectTestsPass("nextErrLine throws an error if there's no more stderr", () {
212 // expectTestsPass("nextErrLine throws an error if there's no more stderr", () { 220 var errors;
213 // var errors; 221 test('test 1', () {
214 // test('test 1', () { 222 currentSchedule.onException.schedule(() {
215 // currentSchedule.onException.schedule(() { 223 errors = currentSchedule.errors;
216 // errors = currentSchedule.errors; 224 });
217 // }); 225
218 // 226 var process = startDartProcess(r'stderr.write("hello\n");');
219 // var process = startDartProcess(r'stderr.write("hello\n");'); 227 expect(process.nextErrLine(), completion(equals('hello')));
220 // expect(process.nextErrLine(), completion(equals('hello'))); 228 expect(process.nextErrLine(), completion(equals('world')));
221 // expect(process.nextErrLine(), completion(equals('world'))); 229 process.shouldExit(0);
222 // process.shouldExit(0); 230 });
223 // }); 231
224 // 232 test('test 2', () {
225 // test('test 2', () { 233 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
226 // expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 234 expect(errors.length, anyOf(1, 2));
227 // expect(errors.length, equals(2)); 235 expect(errors[0].error, isStateError);
228 // expect(errors[0].error, isStateError); 236 expect(errors[0].error.message, equals("No elements"));
229 // expect(errors[0].error.message, equals("No elements")); 237
230 // expect(errors[1].error, matches(r"^Process " 238 // Whether or not this error appears depends on how quickly the "no
231 // r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with " 239 // elements" error is handled.
232 // r"exit code 0\.")); 240 if (errors.length == 2) {
233 // }); 241 expect(errors[1].error, matches(r"^Process "
234 // }, passing: ['test 2']); 242 r"'[^']+[\\/]dart(\.exe)? [^']+' ended earlier than scheduled with "
243 r"exit code 0\."));
244 }
245 });
246 }, passing: ['test 2']);
235 247
236 expectTestsPass("remainingStdout returns all the stdout if it's not consumed " 248 expectTestsPass("remainingStdout returns all the stdout if it's not consumed "
237 "any other way", () { 249 "any other way", () {
238 test('test', () { 250 test('test', () {
239 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");'); 251 var process = startDartProcess(r'print("hello\n\nworld"); print("hi");');
240 process.shouldExit(0); 252 process.shouldExit(0);
241 expect(process.remainingStdout(), 253 expect(process.remainingStdout(),
242 completion(equals("hello\n\nworld\nhi"))); 254 completion(equals("hello\n\nworld\nhi")));
243 }); 255 });
244 }); 256 });
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 process.writeLine("hello"); 338 process.writeLine("hello");
327 expect(process.nextLine(), completion(equals("> hello"))); 339 expect(process.nextLine(), completion(equals("> hello")));
328 process.writeLine("world"); 340 process.writeLine("world");
329 expect(process.nextLine(), completion(equals("> world"))); 341 expect(process.nextLine(), completion(equals("> world")));
330 process.kill(); 342 process.kill();
331 }); 343 });
332 }); 344 });
333 345
334 expectTestsPass("closeStdin closes the process's stdin stream", () { 346 expectTestsPass("closeStdin closes the process's stdin stream", () {
335 test('test', () { 347 test('test', () {
336 currentSchedule.timeout = new Duration(seconds: 1);
337 var process = startDartProcess(r''' 348 var process = startDartProcess(r'''
338 stdin.listen((line) => print("> $line"), 349 stdin.listen((line) => print("> $line"),
339 onDone: () => print("stdin closed")); 350 onDone: () => print("stdin closed"));
340 '''); 351 ''');
341 process.closeStdin(); 352 process.closeStdin();
342 process.shouldExit(0); 353 process.shouldExit(0);
343 expect(process.nextLine(), completion(equals('stdin closed'))); 354 expect(process.nextLine(), completion(equals('stdin closed')));
344 }); 355 });
345 }); 356 });
346 } 357 }
(...skipping 24 matching lines...) Expand all
371 382
372 currentSchedule.onComplete.schedule(() { 383 currentSchedule.onComplete.schedule(() {
373 return tempDir.catchError((_) => null).then((dir) { 384 return tempDir.catchError((_) => null).then((dir) {
374 if (dir == null) return; 385 if (dir == null) return;
375 return new Directory(dir).delete(recursive: true); 386 return new Directory(dir).delete(recursive: true);
376 }); 387 });
377 }, 'clean up temp dir'); 388 }, 'clean up temp dir');
378 389
379 return new ScheduledProcess.start(dartExecutable, ['--checked', dartPath]); 390 return new ScheduledProcess.start(dartExecutable, ['--checked', dartPath]);
380 } 391 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698