diff --git a/runner/main/jobtypes/performance/performance.sh b/runner/main/jobtypes/performance/performance.sh index 31dc01a..9793fa5 100644 --- a/runner/main/jobtypes/performance/performance.sh +++ b/runner/main/jobtypes/performance/performance.sh @@ -30,7 +30,7 @@ function performance_to_env_file() { DBREPLICAS DBHOST_DBREPLICA WEBSERVER - MOODLE_CONFIG + MOODLE_WWWROOT ) echo "${env[@]}" } @@ -44,6 +44,7 @@ function performance_to_summary() { echo "== DBREPLICAS: ${DBREPLICAS}" echo "== MOODLE_CONFIG: ${MOODLE_CONFIG}" echo "== PLUGINSTOINSTALL: ${PLUGINSTOINSTALL}" + echo "== SITESIZE: ${SITESIZE}" } # This job type defines the following env variables @@ -87,9 +88,11 @@ function performance_check() { # Performance job type init. function performance_config() { - EXITCODE=0 + export MOODLE_WWWROOT="http://${WEBSERVER}" + export SITESIZE="${SITESIZE:-XS}" + export COURSENAME="performance_course" } # Performance job type setup. @@ -103,10 +106,6 @@ function performance_setup() { # Performance job type setup for normal mode. function performance_setup_normal() { - - # Create an empty timing file. - touch "${SHAREDDIR}"/timing.json - # Init the Performance site. echo echo ">>> startsection Initialising Performance environment at $(date)<<<" @@ -132,65 +131,42 @@ function performance_initcmd() { # Build the complete init command. cmd=( - php admin/cli/install_database.php --agree-license --fullname="Moodle Performance Test" --shortname="moodle" --adminuser=admin --adminpass=adminpass -- + php admin/cli/install_database.php \ + --agree-license \ + --fullname="Moodle Performance Test"\ + --shortname="moodle" \ + --adminuser=admin \ + --adminpass=adminpass ) } function performance_generate_test_data() { local phpcmd="php" - # Generate courses. - docker exec -t -u www-data "${WEBSERVER}" ${phpcmd} admin/tool/generator/cli/maketestsite.php \ - --size="XS" \ - --fixeddataset \ - --bypasscheck \ - --filesizelimit="1000" - echo "NETWORK: ${NETWORK}" - - # Variables -# WEBSERVER="your_webserver_container" -# phpcmd="php" -# SHAREDDIR="/path/to/shared/dir" # Replace with actual shared directory - SIZE="XS" - SHORTNAME="testcourse_3" - -# Generate the test plan files and capture the output -testplanfiles=$(docker exec -t -u www-data "${WEBSERVER}" ${phpcmd} admin/tool/generator/cli/maketestplan.php \ - --size='XS' \ - --shortname='testcourse_3' \ - --bypasscheck) - -# Display the captured output -echo "Captured Output:" -echo "${testplanfiles}" - -# Extract URLs and download files to ${SHAREDDIR} -urls=$(echo "${testplanfiles}" | grep -oP 'http://[^ ]+') -for url in ${urls}; do - # Extract the filename from the URL - filename=$(basename "${url}") - echo "Downloading: ${url} to ${SHAREDDIR}/${filename}" - curl -o "${SHAREDDIR}/${filename}" "${url}" -done - -echo "All files downloaded to ${SHAREDDIR}." - # Uncomment and handle the test plan files if needed. - # local testplanfiles="$(${testplancommand})" - # if [[ "$testplanfiles" == *"testplan"* ]]; then - # local files=( $testplanfiles ) - # if [ "${#files[*]}" -ne 2 ]; then - # echo "Error: There was a problem generating the test plan." >&2 - # exit 1 - # fi - # ${curlcmd} \ - # -o $FILE_NAME_TEST_PLAN ${files[0]} \ - # -o $FILE_NAME_USERS ${files[1]} \ - # --silent || \ - # throw_error "There was a problem getting the test plan files. Check your wwwroot setting." - # else - # echo "Error: There was a problem generating the test plan." >&2 - # exit 1 - # fi + # Generate Test Site. + local testsitecmd + perfomance_testsite_generator_command testsitecmd # By nameref. + echo "Running: ${testsitecmd[*]}" + docker exec -t -u www-data "${WEBSERVER}" "${testsitecmd[@]}" + + # Generate the test plan files and capture the output + local testplancmd + perfomance_testplan_generator_command testplancmd # By nameref. + echo "Running: ${testplancmd[*]}" + testplanfiles=$(docker exec -t -u www-data "${WEBSERVER}" "${testplancmd[@]}") + + # Display the captured output + echo "Captured Output:" + echo "${testplanfiles}" + + # Extract URLs and download files to ${SHAREDDIR} + urls=$(echo "${testplanfiles}" | grep -oP 'http://[^ ]+') + for url in ${urls}; do + # Extract the filename from the URL + filename=$(basename "${url}") + echo "Downloading: ${url} to /shared/${filename}" + docker exec -it -u www-data "${WEBSERVER}" curl -o "/shared/${filename}" "${url}" + done } #function performance_datacmd() { @@ -199,11 +175,6 @@ echo "All files downloaded to ${SHAREDDIR}." # Performance job type run. function performance_run() { - performance_run_normal -} - -# PHPUnit job tye run for normal mode. -function performance_run_normal() { # Run the job type. echo if [[ RUNCOUNT -gt 1 ]]; then echo ">>> startsection Starting ${RUNCOUNT} Performance main runs at $(date) <<<" @@ -214,36 +185,25 @@ function performance_run_normal() { # Run the job type. # Calculate the command to run. The function will return the command in the passed array. local cmd= - performance_main_command cmd + performance_main_command cmd # By nameref. echo "Running: ${cmd[*]}" - - # Run the command "RUNCOUNT" times. - local iter=1 - while [[ ${iter} -le ${RUNCOUNT} ]]; do - echo - echo ">>> Performance run ${iter} at $(date) <<<" - docker exec -t -u www-data "${WEBSERVER}" "${cmd[@]}" - EXITCODE=$((EXITCODE + $?)) - iter=$((iter+1)) - done + echo ">>> Performance run at $(date) <<<" + docker exec -t "${JMETER}" "${cmd[@]}" + EXITCODE=$? echo "============================================================================" echo "== Date: $(date)" - echo "== Main run exit code: ${EXITCODE}" + echo "== Exit code: ${EXITCODE}" echo "============================================================================" echo ">>> stopsection <<<" - - # If the main run passed, we are done. - if [[ "${EXITCODE}" -eq 0 ]]; then - return - fi } # Performance job type teardown. function performance_teardown() { - # Need to copy the updated timing file back to the workspace. - cp "${SHAREDDIR}"/timing.json "${timingpath}" + # 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" } # Calculate the command to run for Performance main execution, @@ -253,13 +213,51 @@ function performance_teardown() { function performance_main_command() { local -n _cmd=$1 # Return by nameref. - # Let's build the complete perf command for the 1st (parallel) run. + # TODO: Get all of these values from somewhere? + # Build the complete perf command for the run. _cmd=( - php admin/tool/perf/cli/run.php + jmeter \ + -n \ + -j "/shared/logs/jmeter.log" \ + -t "$testplanfile" \ + -Jusersfile="$testusersfile" \ + -Jgroup="$group" \ + -Jdesc="$description" \ + -Jsiteversion="$siteversion" \ + -Jsitebranch="$sitebranch" \ + -Jsitecommit="$sitecommit" \ + $samplerinitstr \ + $includelogsstr \ + $users \ + $loops \ + $rampup \ + $throughput \ + > $runoutput || \ + throw_error $jmetererrormsg ) +} + +function perfomance_testsite_generator_command() { + local -n _cmd=$1 # Return by nameref. - # Add the options and profile. - _cmd+=("${options[@]}") - _cmd+=("${profile[@]}") + # Build the complete perf command for the run. + _cmd=( + php admin/tool/generator/cli/maketestsite.php \ + --size="${SITESIZE}" \ + --fixeddataset \ + --bypasscheck \ + --filesizelimit="1000" + ) } +function performance_testplan_generator_command() { + local -n _cmd=$1 # Return by nameref. + + # Build the complete perf command for the run. + _cmd=( + php admin/tool/generator/cli/maketestplan.php \ + --size="${SITESIZE}" \ + --shortname="${COURSENAME}" \ + --bypasscheck + ) +}