diff --git a/.gitignore b/.gitignore index 207f22f..e2f6593 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ simulated-test-with-php-data-collection/rtc-test-cookies.txt simulated-test-with-php-data-collection/rtc-test.env /rtc-test-cookies.txt + +test-results-[0-9]*.log +submit-response-[0-9]*.log diff --git a/rtc-test.php b/rtc-test.php index d3822d8..0adef9c 100644 --- a/rtc-test.php +++ b/rtc-test.php @@ -503,14 +503,19 @@ function rtctest_register_routes() { 'callback' => 'rtctest_rest_report_all', 'permission_callback' => $cap_check, 'args' => array( - 'poll_delay' => array( + 'poll_delay' => array( 'required' => false, 'type' => 'integer', ), - 'update_size' => array( + 'update_size' => array( 'required' => false, 'type' => 'string', ), + 'save_results' => array( + 'required' => false, + 'type' => 'boolean', + 'default' => false, + ), ), ) ); @@ -875,7 +880,15 @@ function rtctest_rest_report_all( WP_REST_Request $request ) { } } - return rest_ensure_response( array( 'text' => ltrim( $out ) ) ); + $report_text = ltrim( $out ); + + if ( $request->get_param( 'save_results' ) ) { + $timestamp = gmdate( 'Ymd\THis\Z' ); + $path = ABSPATH . 'test-results-' . $timestamp . '.log'; + file_put_contents( $path, $report_text, LOCK_EX ); + } + + return rest_ensure_response( array( 'text' => $report_text ) ); } function rtctest_detect_object_cache_type() { @@ -1071,6 +1084,10 @@ function rtctest_rest_submit( WP_REST_Request $request ) { ) ); + $submission_time = gmdate( 'Ymd\THis\Z' ); + $log_path = ABSPATH . 'submit-response-' . $submission_time . '.log'; + file_put_contents( $log_path, print_r( $response, true ), LOCK_EX ); + if ( is_wp_error( $response ) ) { return new WP_Error( 'submit_failed', $response->get_error_message(), array( 'status' => 502 ) ); } diff --git a/rtc-test.sh b/rtc-test.sh index 65d291c..ee822d6 100755 --- a/rtc-test.sh +++ b/rtc-test.sh @@ -1732,8 +1732,20 @@ cmd_report() { cmd_report_all() { print_header "report-all" require_auth + local url="${PLUGIN_REPORT_ALL_URL}" + local arg + for arg in "$@"; do + case "${arg}" in + --save-results) + case "${url}" in + *\?*) url="${url}&save_results=1" ;; + *) url="${url}?save_results=1" ;; + esac + ;; + esac + done local data - data=$(curl "${BASE_CURL_OPTS[@]}" "${PLUGIN_REPORT_ALL_URL}" 2>/dev/null) || true + data=$(curl "${BASE_CURL_OPTS[@]}" "${url}" 2>/dev/null) || true _print_report_text "${data}" } @@ -2080,7 +2092,7 @@ case "${COMMAND}" in sustain) cmd_sustain ;; env) cmd_env ;; report) cmd_report ;; - report-all) cmd_report_all ;; + report-all) shift; cmd_report_all "$@" ;; submit-results) cmd_submit_results ;; clear) cmd_clear ;; reset) cmd_reset ;; @@ -2113,7 +2125,7 @@ case "${COMMAND}" in printf ' sustain N_CLIENTS independent pollers for DURATION seconds\n' printf ' env Print environment snapshot (PHP, WP, DB, cache, etc.)\n' printf ' report Fetch log from plugin and print summary table\n' - printf ' report-all Print summary by approach × scenario × poll_delay × update_size\n' + printf ' report-all [--save-results] Print summary by approach × scenario × poll_delay × update_size (--save-results writes test-results-TIMESTAMP.log to ABSPATH)\n' printf ' submit-results POST all results to the reporter endpoint (requires REPORTER_* vars)\n' printf ' clear Delete all log entries (table stays, schema intact)\n' printf ' reset Drop the log table entirely (recreated on next tagged request)\n' diff --git a/run.sh b/run.sh index b22366f..89b8583 100755 --- a/run.sh +++ b/run.sh @@ -153,7 +153,7 @@ done bash "${RTC}" reset-approach # ── Results ─────────────────────────────────────────────────────────────────── -bash "${RTC}" report-all +bash "${RTC}" report-all --save-results bash "${RTC}" submit-results printf '\nTotal wall time: %s\n' "$(_run_sh_format_elapsed "${SECONDS}")"