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

Unified Diff: utils/testrunner/pipeline_utils.dart

Issue 11103015: Added the ability for testrunner to start the HTTP server with a random port and communicate that p… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/testrunner/options.dart ('k') | utils/testrunner/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/testrunner/pipeline_utils.dart
===================================================================
--- utils/testrunner/pipeline_utils.dart (revision 13499)
+++ utils/testrunner/pipeline_utils.dart (working copy)
@@ -50,22 +50,22 @@
* Run an external process [cmd] with command line arguments [args].
* [timeout] can be used to forcefully terminate the process after
* some number of seconds. This is used by runCommand and startProcess.
- * If [procId] is 0 (runCommand) then this will return a [Future] for
- * when the process terminates; if [procId] is instead non-zero
- * (startProcess) then a reference to the [Process] will be put in a
- * map with key [procId]; in this case the process can be terminated
- * later by calling [stopProcess] and passing in the [procId].
+ * If [procId] is non-zero (i.e. called from startProcess) then a reference
+ * to the [Process] will be put in a map with key [procId]; in this case
+ * the process can be terminated later by calling [stopProcess] and
+ * passing in the [procId].
+ * [outputMonitor] is an optional function that will be called back with each
+ * line of output from the process.
+ * Returns a [Future] for when the process terminates.
*/
Future _processHelper(String command, List<String> args,
- [int timeout = 300, int procId = 0]) {
- var completer = null;
+ [int timeout = 300, int procId = 0, Function outputMonitor]) {
+ var completer = new Completer();
log.add('Running $command ${Strings.join(args, " ")}');
var timer = null;
var stdoutHandler, stderrHandler;
var process = Process.start(command, args);
- if (procId == 0) {
- completer = new Completer();
- } else {
+ if (procId != 0) {
_procs[procId] = process;
}
process.onStart = () {
@@ -90,13 +90,14 @@
completePipeline(-1);
};
- _pipeStream(process.stdout, stdout);
- _pipeStream(process.stderr, stderr);
+ _pipeStream(process.stdout, stdout, outputMonitor);
+ _pipeStream(process.stderr, stderr, outputMonitor);
- return (completer == null) ? null : completer.future;
+ return completer.future;
}
-void _pipeStream(InputStream stream, List<String> destination) {
+void _pipeStream(InputStream stream, List<String> destination,
+ Function outputMonitor) {
var source = new StringInputStream(stream);
source.onLine = () {
if (source.available() == 0) return;
@@ -106,6 +107,9 @@
// TODO - when we dump the list later skip '###' messages if immediate.
print(line.substring(3));
}
+ if (outputMonitor != null) {
+ outputMonitor(line);
+ }
destination.add(line);
line = source.readLine();
}
@@ -118,27 +122,38 @@
* some number of seconds.
* Returns a [Future] for when the process terminates.
*/
-Future runCommand(String command, List<String> args, [int timeout = 300]) {
- return _processHelper(command, args, timeout);
+Future runCommand(String command, List<String> args,
+ [int timeout = 300, Function outputMonitor]) {
+ return _processHelper(command, args, timeout, outputMonitor:outputMonitor);
}
/**
* Start an external process [cmd] with command line arguments [args].
* Returns an ID by which it can later be stopped.
*/
-int startProcess(String command, List<String> args) {
+int startProcess(String command, List<String> args, [Function outputMonitor]) {
int id = _procId++;
- _processHelper(command, args, 3000, id);
+ _processHelper(command, args, 3000, id,
+ outputMonitor:outputMonitor).then((e) {
+ _procs.remove(id);
+ });
return id;
}
+/** Checks if a process is still running. */
+bool isProcessRunning(int id) {
+ return _procs.containsKey(id);
+}
+
/**
* Stop a process previously started with [startProcess] or [runCommand],
* given the id string.
*/
void stopProcess(int id) {
- Process p = _procs.remove(id);
- p.kill();
+ if (_procs.containsKey(id)) {
+ Process p = _procs.remove(id);
+ p.kill();
+ }
}
/** Delete a file named [fname] if it exists. */
« no previous file with comments | « utils/testrunner/options.dart ('k') | utils/testrunner/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698