Skip to content

Commit

Permalink
Working scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Dec 23, 2024
1 parent e321aa8 commit 0ae9f31
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
27 changes: 7 additions & 20 deletions runner/main/jobtypes/performance/performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ function performance_generate_test_data() {
local testplancmd
performance_testplan_generator_command testplancmd # By nameref.
echo "Running: docker exec -i -t -u www-data "${WEBSERVER}" "${testplancmd[@]}""
echo "_===> PAUSING - Hit Enter to run test <===_"
read
testplanfiles=$(docker exec -i -t -u www-data "${WEBSERVER}" "${testplancmd[@]}")

# Display the captured output
Expand All @@ -164,9 +162,9 @@ function performance_generate_test_data() {

# Ensure the directory exists and is writable
mkdir -p "${SHAREDDIR}/planfiles"
mkdir -p "${SHAREDDIR}/logs"
mkdir -p "${SHAREDDIR}/results"
mkdir -p "${SHAREDDIR}/runs"
mkdir -p "${SHAREDDIR}/output/logs"
mkdir -p "${SHAREDDIR}/output/results"
mkdir -p "${SHAREDDIR}/output/runs"

chmod -R 2777 "${SHAREDDIR}"

Expand Down Expand Up @@ -201,7 +199,7 @@ function performance_run() {
siteversion=""
sitebranch="${MOODLE_BRANCH}"
sitecommit="${MOODLE_BRANCH}"
runoutput="${SHAREDDIR}/results/$datestring.output"
runoutput="${SHAREDDIR}/output/results/$datestring.output"

# Calculate the command to run. The function will return the command in the passed array.
local jmeterruncmd=
Expand All @@ -216,15 +214,11 @@ function performance_run() {
echo docker run ${dockerrunargs[@]} ${jmeterruncmd[@]}
docker run "${dockerrunargs[@]}" ${jmeterruncmd[@]} | tee "${runoutput}"
EXITCODE=$?
echo "============================================================================"
echo "============================================================================"
echo "============================================================================"
read

# Grep the logs looking for errors and warnings.
for errorkey in ERROR WARN; do
# Also checking that the errorkey is the log entry type.
if grep $errorkey "${SHAREDDIR}/logs/jmeter.log" | awk '{print $3}' | grep -q $errorkey ; then
if grep $errorkey "${SHAREDDIR}/output/logs/jmeter.log" | awk '{print $3}' | grep -q $errorkey ; then
echo "Error: \"$errorkey\" found in jmeter logs, read $logfile to see the full trace."
EXITCODE=1
fi
Expand All @@ -239,8 +233,6 @@ read

# Performance job type teardown.
function performance_teardown() {
# Need to copy the results from the jmeter test into the shared directory.
# cp "${SHAREDDIR}"/timing.json "${timingpath}"
echo "TODO: Copy results to results directory for persistence into S3"
}

Expand All @@ -251,12 +243,8 @@ function performance_teardown() {
function performance_main_command() {
local -n _cmd=$1 # Return by nameref.

# Uses the test plan specified in the CLI call.
logfile="logs/jmeter.$datestring.log"

includelogs=1

# Include logs string.
includelogs=1
includelogsstr="-Jincludelogs=$includelogs"
samplerinitstr="-Jbeanshell.listener.init=recorderfunctions.bsf"

Expand All @@ -265,7 +253,7 @@ function performance_main_command() {
# Build the complete perf command for the run.
_cmd=(
-n \
-j "/shared/logs/jmeter.log" \
-j "/shared/output/logs/jmeter.log" \
-t "$testplanfile" \
-Jusersfile="$testusersfile" \
-Jgroup="$group" \
Expand All @@ -276,7 +264,6 @@ function performance_main_command() {
-Jusers=5 -Jloops=1 -Jrampup=1 -Jthroughput=120 \
$samplerinitstr $includelogsstr
)
#$includelogsstr $users $loops $rampup $throughput
}

function perfomance_testsite_generator_command() {
Expand Down
4 changes: 2 additions & 2 deletions runner/main/modules/docker-jmeter/docker-jmeter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function docker-jmeter_setup() {
echo "============================================================================"

# Start the jmeter server
docker pull alpine/jmeter:2.11
docker pull alpine/jmeter:latest

cp -rf "${BASEDIR}"/modules/docker-jmeter/libraries/* "${SHAREDDIR}"

Expand All @@ -64,6 +64,6 @@ function docker-jmeter_run_args() {
-u `id -u` \
-v "${SHAREDDIR}:/shared" \
-w /shared \
alpine/jmeter:2.11
alpine/jmeter:latest
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import org.apache.jmeter.util.JMeterUtils; // http://jakarta.apache.org/jme


testStarted(){
String filenamepath = "runs/tmpfilename.php";
String filenamepath = "output/runs/rundata.php";
FileWriter fstream = new FileWriter(filenamepath, true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("<?php\n");
out.close();
}

testEnded(){
File from = new File("runs/tmpfilename.php");
File from = new File("output/runs/rundata.php");
File to = new File(JMeterUtils.getProperty("filepath"));
from.renameTo(to);
to.setReadable(true, false);
Expand Down
2 changes: 1 addition & 1 deletion runner/main/modules/docker-php/config.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
$CFG->phpunit_prefix = 't_';

// Set the generated users password to avoid the default non-loggeable one.
$CFG->tool_generator_users_password = '%%toolgeneratorpassword%%';
$CFG->tool_generator_users_password = 'toolgeneratorpassword';

if (\moodlehq_ci_runner::job_type_matches('behat')) {
// Configure behat.
Expand Down

0 comments on commit 0ae9f31

Please sign in to comment.