-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·159 lines (133 loc) · 6.11 KB
/
run.sh
File metadata and controls
executable file
·159 lines (133 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# run.sh -- Sets up the test environment, runs the full RTC performance suite
# across all four storage approaches, prints a combined report, and submits
# results to the reporter endpoint.
#
# Prerequisites: WP_PATH (and optionally REPORTER_URL + reporter credentials)
# must be set in .env before running.
#
# Parameter matrix (per approach, after apply-approach):
# POLL_DELAY and UPDATE_SIZE are comma-separated lists (defaults: 0,1 and small,medium,large).
# If either variable is exported in the environment before this script runs, that value wins
# over .env for that axis (same snapshot rule as rtc-test.sh).
#
# Usage:
# bash run.sh
set -euo pipefail
die() { printf 'ERROR: run.sh: %s\n' "$1" >&2; exit 1; }
# Validate whitespace-separated poll-delay tokens (digits only, <=86400; same rules as rtc-test.sh).
_run_sh_validate_poll_delay_list() {
local t out=""
for t in $1; do
case "${t}" in
''|*[!0-9]*) die "invalid POLL_DELAY list token: ${t}" ;;
esac
[ "${t}" -le 86400 ] 2>/dev/null || die "invalid POLL_DELAY list token (max 86400): ${t}"
out="${out}${out:+ }${t}"
done
[ -n "${out}" ] || die "POLL_DELAY list resolved to empty"
printf '%s' "${out}"
}
_run_sh_validate_update_size_list() {
local t out=""
for t in $1; do
case "${t}" in
small|medium|large) out="${out}${out:+ }${t}" ;;
*) die "invalid UPDATE_SIZE list token: ${t}" ;;
esac
done
[ -n "${out}" ] || die "UPDATE_SIZE list resolved to empty"
printf '%s' "${out}"
}
# _run_sh_format_elapsed SECONDS -- human-readable duration for stdout summary
_run_sh_format_elapsed() {
local sec="${1:-0}" h m s
h=$(( sec / 3600 ))
m=$(( (sec % 3600) / 60 ))
s=$(( sec % 60 ))
if [ "${h}" -gt 0 ]; then
printf '%dh %dm %ds' "${h}" "${m}" "${s}"
elif [ "${m}" -gt 0 ]; then
printf '%dm %ds' "${m}" "${s}"
else
printf '%ds' "${s}"
fi
}
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
RTC="${SCRIPT_DIR}/rtc-test.sh"
ENV_FILE="${SCRIPT_DIR}/.env"
# Snapshot POLL_DELAY / UPDATE_SIZE before .env so exported values win over the file.
_pre_pin_poll=0
[ "${POLL_DELAY+x}" = x ] && _pre_pin_poll=1 && _pre_poll="${POLL_DELAY}"
_pre_pin_sz=0
[ "${UPDATE_SIZE+x}" = x ] && _pre_pin_sz=1 && _pre_sz="${UPDATE_SIZE}"
# Source .env without exporting (no `set -a`). Exporting WP_NONCE here would stick in this
# shell after `setup` rewrites .env; child `bash rtc-test.sh` processes would inherit the stale
# nonce and rtc-test.sh would restore it over the file — REST calls fail with rest_cookie_invalid_nonce.
if [ -f "${ENV_FILE}" ]; then
# shellcheck source=/dev/null
. "${ENV_FILE}"
fi
[ "${_pre_pin_poll}" = 1 ] && POLL_DELAY="${_pre_poll}"
[ "${_pre_pin_sz}" = 1 ] && UPDATE_SIZE="${_pre_sz}"
# Comma-separated lists; commas -> spaces for iteration. Defaults when unset/empty after .env.
_poll_raw=""
if [ "${_pre_pin_poll}" = 1 ]; then
_poll_raw="${POLL_DELAY}"
elif [ -n "${POLL_DELAY:-}" ]; then
_poll_raw="${POLL_DELAY}"
else
_poll_raw="0,1"
fi
_sz_raw=""
if [ "${_pre_pin_sz}" = 1 ]; then
_sz_raw="${UPDATE_SIZE}"
elif [ -n "${UPDATE_SIZE:-}" ]; then
_sz_raw="${UPDATE_SIZE}"
else
_sz_raw="small,medium,large"
fi
RTC_POLL_DELAYS="$(_run_sh_validate_poll_delay_list "${_poll_raw//,/ }")"
RTC_UPDATE_SIZES="$(_run_sh_validate_update_size_list "${_sz_raw//,/ }")"
unset _pre_pin_poll _pre_poll _pre_pin_sz _pre_sz
# Drop auth vars from this shell so every rtc-test.sh child reads them from .env only.
# (Avoids stale WP_NONCE inherited from the parent process after setup rewrites the file.)
unset WP_NONCE WP_COOKIE_JAR 2>/dev/null || true
SECONDS=0
# ── One-time setup ────────────────────────────────────────────────────────────
# Installs the MU-plugin, creates the rtctest user and test post, verifies the
# required WordPress version, and writes credentials to .env.
bash "${RTC}" setup
# ── Clear any log data from previous runs ─────────────────────────────────────
# report-all and submit-results aggregate everything in the log table, so stale
# rows from a prior run would skew the averages. Clear before each full suite.
bash "${RTC}" clear
# ── Environment snapshot ──────────────────────────────────────────────────────
bash "${RTC}" env
# ── Per-approach test loop ────────────────────────────────────────────────────
# For each approach: patch WP, reset RTC state, then run baseline / single-idle /
# sustain for every (POLL_DELAY × UPDATE_SIZE) combination.
APPROACHES="post-meta custom-table post-meta-transients custom-table-with-transients"
printf '\n── Matrix: POLL_DELAY ∈ {%s}, UPDATE_SIZE ∈ {%s} ──\n' \
"${RTC_POLL_DELAYS// /, }" "${RTC_UPDATE_SIZES// /, }"
for approach in ${APPROACHES}; do
bash "${RTC}" apply-approach "${approach}"
for poll_delay in ${RTC_POLL_DELAYS}; do
for update_size in ${RTC_UPDATE_SIZES}; do
APPROACH="${approach}" POLL_DELAY="${poll_delay}" UPDATE_SIZE="${update_size}" \
bash "${RTC}" print-test-conditions "${approach}"
APPROACH="${approach}" POLL_DELAY="${poll_delay}" UPDATE_SIZE="${update_size}" \
bash "${RTC}" baseline
APPROACH="${approach}" POLL_DELAY="${poll_delay}" UPDATE_SIZE="${update_size}" \
bash "${RTC}" single-idle
APPROACH="${approach}" POLL_DELAY="${poll_delay}" UPDATE_SIZE="${update_size}" \
bash "${RTC}" sustain
done
done
done
# ── Reset to RC2 baseline after the final approach ────────────────────────────
bash "${RTC}" reset-approach
# ── Results ───────────────────────────────────────────────────────────────────
bash "${RTC}" report-all
bash "${RTC}" submit-results
printf '\nTotal wall time: %s\n' "$(_run_sh_format_elapsed "${SECONDS}")"