atharvalade commented on code in PR #2920:
URL: https://github.com/apache/iggy/pull/2920#discussion_r2926639930
##########
scripts/utils.sh:
##########
@@ -149,3 +149,196 @@ function on_exit_bench() {
done
fi
}
+
+# ---------------------------------------------------------------------------
+# Server lifecycle helpers for example-runner scripts
+# ---------------------------------------------------------------------------
+
+readonly EXAMPLES_LOG_FILE="iggy-server.log"
+readonly EXAMPLES_PID_FILE="iggy-server.pid"
+readonly EXAMPLES_SERVER_TIMEOUT=300
+
+# Resolve and validate the server binary path.
+# Usage: resolve_server_binary [target]
+# Sets global SERVER_BIN.
+function resolve_server_binary() {
+ local target="${1:-}"
+ if [ -n "${target}" ]; then
+ SERVER_BIN="target/${target}/debug/iggy-server"
+ else
+ SERVER_BIN="target/debug/iggy-server"
+ fi
+
+ if [ ! -f "${SERVER_BIN}" ]; then
+ echo "Error: Server binary not found at ${SERVER_BIN}"
+ echo "Please build the server binary before running this script:"
+ if [ -n "${target}" ]; then
+ echo " cargo build --target ${target} --bin iggy-server"
+ else
+ echo " cargo build --bin iggy-server"
+ fi
+ exit 1
+ fi
+ echo "Using server binary at ${SERVER_BIN}"
+}
+
+# Resolve and validate the CLI binary path.
+# Usage: resolve_cli_binary [target]
+# Sets global CLI_BIN.
+function resolve_cli_binary() {
+ local target="${1:-}"
+ if [ -n "${target}" ]; then
+ CLI_BIN="target/${target}/debug/iggy"
+ else
+ CLI_BIN="target/debug/iggy"
+ fi
+
+ if [ ! -f "${CLI_BIN}" ]; then
+ echo "Error: CLI binary not found at ${CLI_BIN}"
+ echo "Please build the CLI and examples before running this script:"
+ if [ -n "${target}" ]; then
+ echo " cargo build --target ${target} --bin iggy --examples"
+ else
+ echo " cargo build --bin iggy --examples"
+ fi
+ exit 1
+ fi
+ echo "Using CLI binary at ${CLI_BIN}"
+}
+
+# Remove old server data, log, and PID files.
+function cleanup_server_state() {
+ rm -fr local_data
+ rm -f "${EXAMPLES_LOG_FILE}" "${EXAMPLES_PID_FILE}"
+}
+
+# Start the plain (non-TLS) iggy server in background.
+# Usage: start_plain_server [extra_args...]
+function start_plain_server() {
+ echo "Starting server from ${SERVER_BIN}..."
+ IGGY_ROOT_USERNAME=iggy IGGY_ROOT_PASSWORD=iggy \
+ ${SERVER_BIN} "$@" &>"${EXAMPLES_LOG_FILE}" &
+ echo $! >"${EXAMPLES_PID_FILE}"
+}
+
+# Start the TLS-enabled iggy server in background.
+# Usage: start_tls_server [extra_args...]
+function start_tls_server() {
+ echo "Starting TLS server from ${SERVER_BIN}..."
+ IGGY_ROOT_USERNAME=iggy IGGY_ROOT_PASSWORD=iggy \
+ IGGY_TCP_TLS_ENABLED=true \
+ IGGY_TCP_TLS_CERT_FILE=core/certs/iggy_cert.pem \
+ IGGY_TCP_TLS_KEY_FILE=core/certs/iggy_key.pem \
+ ${SERVER_BIN} "$@" &>"${EXAMPLES_LOG_FILE}" &
+ echo $! >"${EXAMPLES_PID_FILE}"
+}
+
+# Block until "has started" appears in the server log or timeout.
+# Usage: wait_for_server_ready [label]
+function wait_for_server_ready() {
+ local label="${1:-Iggy}"
+ local elapsed=0
+ while ! grep -q "has started" "${EXAMPLES_LOG_FILE}"; do
+ if [ ${elapsed} -gt ${EXAMPLES_SERVER_TIMEOUT} ]; then
+ echo "${label} server did not start within
${EXAMPLES_SERVER_TIMEOUT} seconds."
+ ps fx 2>/dev/null || ps aux
+ cat "${EXAMPLES_LOG_FILE}"
+ exit 1
+ fi
+ echo "Waiting for ${label} server to start... ${elapsed}"
+ sleep 1
+ ((elapsed += 1))
+ done
+}
+
+# Gracefully stop the server using the PID file.
+function stop_server() {
+ if [ -e "${EXAMPLES_PID_FILE}" ]; then
+ kill -TERM "$(cat "${EXAMPLES_PID_FILE}")" 2>/dev/null || true
+ sleep 2
+ rm -f "${EXAMPLES_PID_FILE}"
+ fi
+}
+
+# Print final result and dump the log on failure.
+function report_result() {
+ local exit_code=$1
+ if [ "${exit_code}" -eq 0 ]; then
+ echo "Test passed"
+ else
+ echo "Test failed, see log file:"
+ test -e "${EXAMPLES_LOG_FILE}" && cat "${EXAMPLES_LOG_FILE}"
+ fi
+ rm -f "${EXAMPLES_LOG_FILE}" "${EXAMPLES_PID_FILE}"
+}
+
+# Portable timeout wrapper (macOS has gtimeout via coreutils, Linux has
timeout).
+function portable_timeout() {
+ local secs="$1"
+ shift
+ if command -v timeout >/dev/null 2>&1; then
+ timeout "${secs}" "$@"
+ elif command -v gtimeout >/dev/null 2>&1; then
+ gtimeout "${secs}" "$@"
+ else
+ "$@"
+ fi
+}
+
+# Run commands extracted from a README file.
+# Usage: run_readme_commands readme_file grep_pattern [cmd_timeout]
+# Reads matching lines, strips backticks/comments, executes each.
+# Calls TRANSFORM_COMMAND function on each command if defined.
+# Returns: sets global EXAMPLES_EXIT_CODE.
+function run_readme_commands() {
Review Comment:
Added optional `grep_exclude` parameter to `run_readme_commands` and removed
the duplicated inline loop
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]