From 553f9eca4ea51f99a499d8a9abdd2aa88db4d1e4 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Mon, 4 May 2026 09:38:06 -0400 Subject: [PATCH 1/3] The log should be cerated when no results submit. --- rtc-test.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/rtc-test.php b/rtc-test.php index 921cfc4..1ab29a2 100644 --- a/rtc-test.php +++ b/rtc-test.php @@ -1026,24 +1026,9 @@ function rtctest_rest_submit( WP_REST_Request $request ) { } } - $response = wp_remote_post( - rtrim( $reporter_url, '/' ) . '/wp-json/wp-unit-test-api/v1/rtc-performance-results', - array( - 'headers' => array( - 'Content-Type' => 'application/json', - 'Authorization' => 'Basic ' . base64_encode( $api_key ), - ), - 'body' => wp_json_encode( array( - 'environment_name' => $environment_name, - 'env' => $env, - 'results' => $results, - ) ), - 'timeout' => 30, - ) - ); - $submission_time = gmdate( 'Ymd\THis\Z' ); - $report_log = implode( + $log_path = path_join( dirname( __FILE__ ), 'report-submission-' . $submission_time . '.log' ); + $report_log_head = implode( "\n", array( 'RTC performance report — submission log', @@ -1063,11 +1048,27 @@ function rtctest_rest_submit( WP_REST_Request $request ) { '', '------Response-------', '', - print_r( $response, true ), - '', ) ); - file_put_contents( path_join( dirname( __FILE__ ), 'report-submission-' . $submission_time . '.log' ), $report_log ); + file_put_contents( $log_path, $report_log_head, LOCK_EX ); + + $response = wp_remote_post( + rtrim( $reporter_url, '/' ) . '/wp-json/wp-unit-test-api/v1/rtc-performance-results', + array( + 'headers' => array( + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode( $api_key ), + ), + 'body' => wp_json_encode( array( + 'environment_name' => $environment_name, + 'env' => $env, + 'results' => $results, + ) ), + 'timeout' => 30, + ) + ); + + file_put_contents( $log_path, print_r( $response, true ) . "\n", FILE_APPEND | LOCK_EX ); if ( is_wp_error( $response ) ) { return new WP_Error( 'submit_failed', $response->get_error_message(), array( 'status' => 502 ) ); From 87b229d48aa3b07dc698e73f3f44c5af85220723 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Mon, 4 May 2026 21:34:25 -0400 Subject: [PATCH 2/3] Improvements to the log creation. - Place file in the `ABSPATH` directory. - Log the submission response and the test results separately. --- rtc-test.php | 49 +++++++++++++++++++------------------------------ rtc-test.sh | 18 +++++++++++++++--- run.sh | 2 +- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/rtc-test.php b/rtc-test.php index 1ab29a2..c1cba1a 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() { @@ -1026,32 +1039,6 @@ function rtctest_rest_submit( WP_REST_Request $request ) { } } - $submission_time = gmdate( 'Ymd\THis\Z' ); - $log_path = path_join( dirname( __FILE__ ), 'report-submission-' . $submission_time . '.log' ); - $report_log_head = implode( - "\n", - array( - 'RTC performance report — submission log', - 'Submitted at (UTC): ' . $submission_time, - '', - '------Environment Name-------', - '', - $environment_name, - '', - '------Env-------', - '', - print_r( $env, true ), - '', - '------Results-------', - '', - print_r( $results, true ), - '', - '------Response-------', - '', - ) - ); - file_put_contents( $log_path, $report_log_head, LOCK_EX ); - $response = wp_remote_post( rtrim( $reporter_url, '/' ) . '/wp-json/wp-unit-test-api/v1/rtc-performance-results', array( @@ -1068,7 +1055,9 @@ function rtctest_rest_submit( WP_REST_Request $request ) { ) ); - file_put_contents( $log_path, print_r( $response, true ) . "\n", FILE_APPEND | LOCK_EX ); + $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}")" From 91904cb7f227a8f73cee60cc2f234f2ac9d4284d Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com> Date: Mon, 4 May 2026 21:39:09 -0400 Subject: [PATCH 3/3] Ignore any log files created. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) 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