Skip to content

Instantly share code, notes, and snippets.

@munificent
Created March 19, 2013 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munificent/5199833 to your computer and use it in GitHub Desktop.
Save munificent/5199833 to your computer and use it in GitHub Desktop.
This is my little script for stress-testing a Dart program. Change `script_to_run.dart` to the name of the Dart script to run. Make sure that script ends with a non-zero exit code to indicate failure.
import 'dart:io';
const MAX_ATTEMPTS = 10000;
const MAX_JOBS = 20;
var total = 0;
var numRunning = 0;
main() {
for (var i = 0; i < MAX_JOBS; i++) spawnProc();
}
spawnProc() {
numRunning++;
Process.run('dart', ['--checked', 'script_to_run.dart']).then((result) {
total++;
numRunning--;
if (result.exitCode != 0) {
print("$total $numRunning: ${result.exitCode} ${result.stdout}");
}
if (total < MAX_ATTEMPTS && numRunning < MAX_JOBS) spawnProc();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment