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

Side by Side Diff: utils/tests/pub/test_pub.dart

Issue 11474046: Make sure to drain stderr in tests so that spawned process doesn't hang. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add bug. Created 8 years 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 | « utils/pub/log.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub 6 * Test infrastructure for testing pub. Unlike typical unit tests, most pub
7 * tests are integration tests that stage some stuff on the file system, run 7 * tests are integration tests that stage some stuff on the file system, run
8 * pub, and then validate the results. This library provides an API to build 8 * pub, and then validate the results. This library provides an API to build
9 * tests like that. 9 * tests like that.
10 */ 10 */
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 return Entrypoint.load(join(sandboxDir, appPath), cache) 1261 return Entrypoint.load(join(sandboxDir, appPath), cache)
1262 .chain((entrypoint) { 1262 .chain((entrypoint) {
1263 var validator = fn(entrypoint); 1263 var validator = fn(entrypoint);
1264 return validator.validate().transform((_) { 1264 return validator.validate().transform((_) {
1265 return new Pair(validator.errors, validator.warnings); 1265 return new Pair(validator.errors, validator.warnings);
1266 }); 1266 });
1267 }); 1267 });
1268 }); 1268 });
1269 } 1269 }
1270 1270
1271 /// A matcher that matches a Pair.» 1271 /// A matcher that matches a Pair.
1272 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) => 1272 Matcher pairOf(Matcher firstMatcher, Matcher lastMatcher) =>
1273 new _PairMatcher(firstMatcher, lastMatcher); 1273 new _PairMatcher(firstMatcher, lastMatcher);
1274 1274
1275 class _PairMatcher extends BaseMatcher { 1275 class _PairMatcher extends BaseMatcher {
1276 final Matcher _firstMatcher; 1276 final Matcher _firstMatcher;
1277 final Matcher _lastMatcher; 1277 final Matcher _lastMatcher;
1278 1278
1279 _PairMatcher(this._firstMatcher, this._lastMatcher); 1279 _PairMatcher(this._firstMatcher, this._lastMatcher);
1280 1280
1281 bool matches(item, MatchState matchState) { 1281 bool matches(item, MatchState matchState) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 /// Whether the user has scheduled the end of this process by calling either 1327 /// Whether the user has scheduled the end of this process by calling either
1328 /// [shouldExit] or [kill]. 1328 /// [shouldExit] or [kill].
1329 bool _endScheduled = false; 1329 bool _endScheduled = false;
1330 1330
1331 /// Whether the process is expected to terminate at this point. 1331 /// Whether the process is expected to terminate at this point.
1332 bool _endExpected = false; 1332 bool _endExpected = false;
1333 1333
1334 /// Wraps a [Process] [Future] in a scheduled process. 1334 /// Wraps a [Process] [Future] in a scheduled process.
1335 ScheduledProcess(this.name, Future<Process> process) 1335 ScheduledProcess(this.name, Future<Process> process)
1336 : _process = process, 1336 : _process = process,
1337 _stdout = process.transform((p) => new StringInputStream(p.stdout)), 1337 _stdout = process.transform((p) => _wrapStream(p.stdout)),
1338 _stderr = process.transform((p) => new StringInputStream(p.stderr)) { 1338 _stderr = process.transform((p) => _wrapStream(p.stderr)) {
1339 1339
1340 _schedule((_) { 1340 _schedule((_) {
1341 if (!_endScheduled) { 1341 if (!_endScheduled) {
1342 throw new StateError("Scheduled process $name must have shouldExit() " 1342 throw new StateError("Scheduled process $name must have shouldExit() "
1343 "or kill() called before the test is run."); 1343 "or kill() called before the test is run.");
1344 } 1344 }
1345 1345
1346 return _process.transform((p) { 1346 return _process.transform((p) {
1347 p.onExit = (c) { 1347 p.onExit = (c) {
1348 if (_endExpected) { 1348 if (_endExpected) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 _endExpected = true; 1459 _endExpected = true;
1460 return timeout(_exitCode, _SCHEDULE_TIMEOUT, 1460 return timeout(_exitCode, _SCHEDULE_TIMEOUT,
1461 "waiting for process $name to exit").transform((exitCode) { 1461 "waiting for process $name to exit").transform((exitCode) {
1462 if (expectedExitCode != null) { 1462 if (expectedExitCode != null) {
1463 expect(exitCode, equals(expectedExitCode)); 1463 expect(exitCode, equals(expectedExitCode));
1464 } 1464 }
1465 }); 1465 });
1466 }); 1466 });
1467 } 1467 }
1468 1468
1469 /// Wraps [source] and ensures it gets eagerly drained. We do this to make
1470 /// sure a process will exit even if we don't care about its output.
1471 static Future<StringInputStream> _wrapStream(InputStream source) {
1472 return new StringInputStream(wrapInputStream(source));
1473 }
1474
1469 /// Prints the remaining data in the process's stdout and stderr streams. 1475 /// Prints the remaining data in the process's stdout and stderr streams.
1470 /// Prints nothing if the straems are empty. 1476 /// Prints nothing if the straems are empty.
1471 Future _printStreams() { 1477 Future _printStreams() {
1472 Future printStream(String streamName, StringInputStream stream) { 1478 Future printStream(String streamName, StringInputStream stream) {
1473 return consumeStringInputStream(stream).transform((output) { 1479 return consumeStringInputStream(stream).transform((output) {
1474 if (output.isEmpty) return; 1480 if (output.isEmpty) return;
1475 1481
1476 print('\nProcess $name $streamName:'); 1482 print('\nProcess $name $streamName:');
1477 for (var line in output.trim().split("\n")) { 1483 for (var line in output.trim().split("\n")) {
1478 print('| $line'); 1484 print('| $line');
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 /// calling [completion] is unnecessary. 1637 /// calling [completion] is unnecessary.
1632 void expectLater(Future actual, matcher, {String reason, 1638 void expectLater(Future actual, matcher, {String reason,
1633 FailureHandler failureHandler, bool verbose: false}) { 1639 FailureHandler failureHandler, bool verbose: false}) {
1634 _schedule((_) { 1640 _schedule((_) {
1635 return actual.transform((value) { 1641 return actual.transform((value) {
1636 expect(value, matcher, reason: reason, failureHandler: failureHandler, 1642 expect(value, matcher, reason: reason, failureHandler: failureHandler,
1637 verbose: false); 1643 verbose: false);
1638 }); 1644 });
1639 }); 1645 });
1640 } 1646 }
OLDNEW
« no previous file with comments | « utils/pub/log.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698