Skip to content

Commit

Permalink
Task 54140: automatically start load from pipeline rather than requir…
Browse files Browse the repository at this point in the history
…ing start button in UI
  • Loading branch information
Robin Bobbitt committed Feb 9, 2016
1 parent add5569 commit e1cb879
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
58 changes: 58 additions & 0 deletions autoLoadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
$application = getenv("VCAP_APPLICATION");
$application_json = json_decode($application, true);
$applicationURI = $application_json["application_uris"][0];

if (!isset($_GET['action']) || $_GET['action'] == 'status') {
//Show status of load testing
if (file_exists("RUNNING")) {
echo "Load test is running. ";
echo file_get_contents("RUNNING");
} else {
echo "Load test is not running. Use http://$applicationURI/autoLoadTest.php?count=COUNT&delay=DELAY&action=start to start load testing.";
}
} else if ($_GET['action'] == 'stop') {
//Turn off load test
exec('rm -f RUNNING');
print "Load test is stopped.\n";
} else if ($_GET['action'] == 'start') {
//If already running, tell user to issue a stop first. We could fancier and kill
//the running script and update with the new params but for now let's just...
if (file_exists("RUNNING")) {
print("Load test is already running. Use http://$applicationURI/autoLoadTest.php?action=stop to stop the running test.");
exit();
}

//Calculate route to catalog loadTest URL
$applicationName = $application_json["name"];
$catalogAppName = str_replace("ui-", "catalog-api-", $applicationName);
$catalogAppName = str_replace("-ui", "-catalog-api", $catalogAppName);
$catalogHost=substr_replace($applicationURI, $catalogAppName, 0, strlen($applicationName));
$catalogRoute = "http://" . $catalogHost;

//Specify count in loadTest URL
if (isset($_GET['count'])) {
$count = $_GET['count'];
} else {
$count = 100;
}
$url = $catalogRoute . "/loadTest?count=" . $count;

//Specify the delay between calls to loadTest
if (isset($_GET['delay'])) {
$delay = $_GET['delay'];
} else {
$delay = 0;
}

//Use a RUNNING file to indicate load test is running
echo exec("echo 'Count: $count Delay: $delay' > RUNNING");

//Start the load script in the background and return
#Print "load.sh -d $delay -u $url\n";
echo exec("sh load.sh -d $delay -u $url > load.log 2>&1 &");
print "Loaded started with delay $delay on $url\n";
} else {
print "Unsupported action {$_GET['action']}";
}
?>
59 changes: 59 additions & 0 deletions load.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh
# This script generates load on the specified URL.

#Accepts a delay and a URL

while getopts :d:u: opt; do
case $opt in
d) #set delay
DELAY=$OPTARG
#echo "DELAY = $DELAY"
;;
u) #set url
URL=$OPTARG
#echo "URL = $URL"
;;
\?) #invalid arg
echo "Invalid argument -$OPTARG"
exit 1;
;;
esac
done

if [ -z "$URL" ]; then
echo "URL must be specified with -u";
exit 1;
fi

#Default delay to 0 if not specified
if [ -z "$DELAY" ]; then
DELAY=0;
fi

#echo "Delay: $DELAY";

#Check for RUNNING file to determine if load should be generated
if [ ! -f "RUNNING" ] ; then
echo "Load test not running. Exiting...";
exit 0;
fi

#Clean up the results log file if it exists
if [ -f results.log ] ; then
echo "Cleaning up old results.log"
rm -f results.log
fi

#TODO: Get fancier to prevent someone from stopping and starting the load during sleep interval
# and ending up with multiple load scripts continuing to run simultaneously. For example, could
# put the PID in RUNNING and either verify it here or have the calling script kill this process.

echo "Starting load to $URL";

while [ -f RUNNING ] ;
do
curl -s $URL -w "\n" >> results.log;
sleep $DELAY;
done

echo "Done.";

0 comments on commit e1cb879

Please sign in to comment.