hubcio commented on code in PR #2920:
URL: https://github.com/apache/iggy/pull/2920#discussion_r2923756765


##########
scripts/run-python-examples-from-readme.sh:
##########


Review Comment:
   you silently removed support for python TLS testing, because old examples 
had them hardcoded, seelines 182,183. IMHO you should add these to python 
README.md



##########
scripts/run-examples-from-readme.sh:
##########
@@ -0,0 +1,545 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Unified script to run SDK examples from README.md files.
+# Usage: ./scripts/run-examples-from-readme.sh [OPTIONS]
+#
+#   --language LANG   Language to test: rust|go|node|python|java|csharp 
(default: all)
+#   --target TARGET   Cargo target architecture for the server binary
+#   --skip-tls        Skip TLS example tests
+#   --goos GOOS       Go OS target
+#   --goarch GOARCH   Go architecture target
+#   --csharpos OS     C# --os flag
+#   --csharparch ARCH C# --arch flag

Review Comment:
   why do we need these? i would assume that it should use host OS/arch



##########
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:
   Lines 119-157 reimplement the loop from run_readme_commands (lines 293-344) 
because of the grep_exclude parameter. The run_readme_commands function doesn't 
support exclusion patterns. adding an optional exclude parameter would 
eliminate the duplication



##########
scripts/run-examples-from-readme.sh:
##########
@@ -0,0 +1,545 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Unified script to run SDK examples from README.md files.
+# Usage: ./scripts/run-examples-from-readme.sh [OPTIONS]
+#
+#   --language LANG   Language to test: rust|go|node|python|java|csharp 
(default: all)
+#   --target TARGET   Cargo target architecture for the server binary
+#   --skip-tls        Skip TLS example tests
+#   --goos GOOS       Go OS target
+#   --goarch GOARCH   Go architecture target
+#   --csharpos OS     C# --os flag
+#   --csharparch ARCH C# --arch flag
+#
+# The script sources shared utilities from scripts/utils.sh, starts the iggy
+# server (built from source), parses example commands from each language's
+# README.md, and executes them. Non-TLS examples run first; then the server
+# is restarted with TLS for TLS-specific examples.
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# shellcheck source=scripts/utils.sh
+source "${SCRIPT_DIR}/utils.sh"
+
+ROOT_WORKDIR="$(pwd)"
+
+# ---------------------------------------------------------------------------
+# Argument parsing
+# ---------------------------------------------------------------------------
+LANGUAGE="all"
+TARGET=""
+SKIP_TLS=false
+GOOS=""
+GOARCH=""
+CSOS=""
+CSARCH=""
+
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --language)   LANGUAGE="$2";  shift 2 ;;
+        --target)     TARGET="$2";    shift 2 ;;
+        --skip-tls)   SKIP_TLS=true;  shift   ;;
+        --goos)       GOOS="$2";      shift 2 ;;
+        --goarch)     GOARCH="$2";    shift 2 ;;
+        --csharpos)   CSOS="$2";      shift 2 ;;
+        --csharparch) CSARCH="$2";    shift 2 ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--language LANG] [--target TARGET] [--skip-tls] 
[--goos GOOS] [--goarch GOARCH] [--csharpos OS] [--csharparch ARCH]"
+            exit 1
+            ;;
+    esac
+done
+
+# ---------------------------------------------------------------------------
+# Helpers
+# ---------------------------------------------------------------------------
+
+# Run a full non-TLS + TLS cycle for one language.
+# Arguments:
+#   $1 - language label (for logging)
+#   $2 - working directory (relative to repo root, or "." for root)
+#   $3 - space-separated list of README files (relative to workdir)
+#   $4 - grep pattern for non-TLS commands
+#   $5 - grep exclude pattern for non-TLS commands (empty = no exclude)
+#   $6 - grep pattern for TLS commands (empty = no TLS examples)
+#   $7 - per-command timeout in seconds (0 = no timeout)
+#   $8 - extra server args (e.g. "--fresh")
+# shellcheck disable=SC2329
+run_language_examples() {
+    local lang="$1"
+    local workdir="$2"
+    local readme_files="$3"
+    local grep_pattern="$4"
+    local grep_exclude="$5"
+    local tls_grep_pattern="$6"
+    local cmd_timeout="$7"
+    local server_extra_args="$8"
+
+    echo ""
+    echo "============================================================"
+    echo "  Running ${lang} examples"
+    echo "============================================================"
+    echo ""
+
+    EXAMPLES_EXIT_CODE=0

Review Comment:
   this is a bit messy: multiple functions initialize, read, and write this 
global: run_language_examples (line 103), run_rust_examples (line 232), 
run_csharp_examples (line 435), run_python_examples (line 359), and 
run_readme_commands (line 331). In --language all mode, this shared state 
persists across run_one calls. run_one does set +e and captures the return 
code, but if a language function forgets to reinitialize EXAMPLES_EXIT_CODE, 
stale failure state could carry over (or mask a failure).



##########
scripts/run-examples-from-readme.sh:
##########
@@ -0,0 +1,545 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Unified script to run SDK examples from README.md files.
+# Usage: ./scripts/run-examples-from-readme.sh [OPTIONS]
+#
+#   --language LANG   Language to test: rust|go|node|python|java|csharp 
(default: all)
+#   --target TARGET   Cargo target architecture for the server binary
+#   --skip-tls        Skip TLS example tests
+#   --goos GOOS       Go OS target
+#   --goarch GOARCH   Go architecture target
+#   --csharpos OS     C# --os flag
+#   --csharparch ARCH C# --arch flag
+#
+# The script sources shared utilities from scripts/utils.sh, starts the iggy
+# server (built from source), parses example commands from each language's
+# README.md, and executes them. Non-TLS examples run first; then the server
+# is restarted with TLS for TLS-specific examples.
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# shellcheck source=scripts/utils.sh
+source "${SCRIPT_DIR}/utils.sh"
+
+ROOT_WORKDIR="$(pwd)"
+
+# ---------------------------------------------------------------------------
+# Argument parsing
+# ---------------------------------------------------------------------------
+LANGUAGE="all"
+TARGET=""
+SKIP_TLS=false
+GOOS=""
+GOARCH=""
+CSOS=""
+CSARCH=""
+
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --language)   LANGUAGE="$2";  shift 2 ;;
+        --target)     TARGET="$2";    shift 2 ;;
+        --skip-tls)   SKIP_TLS=true;  shift   ;;
+        --goos)       GOOS="$2";      shift 2 ;;
+        --goarch)     GOARCH="$2";    shift 2 ;;
+        --csharpos)   CSOS="$2";      shift 2 ;;
+        --csharparch) CSARCH="$2";    shift 2 ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--language LANG] [--target TARGET] [--skip-tls] 
[--goos GOOS] [--goarch GOARCH] [--csharpos OS] [--csharparch ARCH]"
+            exit 1
+            ;;
+    esac
+done
+
+# ---------------------------------------------------------------------------
+# Helpers
+# ---------------------------------------------------------------------------
+
+# Run a full non-TLS + TLS cycle for one language.
+# Arguments:
+#   $1 - language label (for logging)
+#   $2 - working directory (relative to repo root, or "." for root)
+#   $3 - space-separated list of README files (relative to workdir)
+#   $4 - grep pattern for non-TLS commands
+#   $5 - grep exclude pattern for non-TLS commands (empty = no exclude)
+#   $6 - grep pattern for TLS commands (empty = no TLS examples)
+#   $7 - per-command timeout in seconds (0 = no timeout)
+#   $8 - extra server args (e.g. "--fresh")
+# shellcheck disable=SC2329
+run_language_examples() {
+    local lang="$1"
+    local workdir="$2"
+    local readme_files="$3"
+    local grep_pattern="$4"
+    local grep_exclude="$5"
+    local tls_grep_pattern="$6"
+    local cmd_timeout="$7"
+    local server_extra_args="$8"
+
+    echo ""
+    echo "============================================================"
+    echo "  Running ${lang} examples"
+    echo "============================================================"
+    echo ""
+
+    EXAMPLES_EXIT_CODE=0
+
+    # --- Non-TLS pass ---
+    cleanup_server_state
+    # shellcheck disable=SC2086
+    start_plain_server ${server_extra_args}
+    wait_for_server_ready "${lang}"
+
+    if [ "${workdir}" != "." ]; then
+        cd "${workdir}"
+    fi
+
+    for readme in ${readme_files}; do
+        if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+            break
+        fi
+        if [ -n "${grep_exclude}" ]; then
+            # Build a combined pattern that filters out the exclude
+            local filtered
+            filtered=$(grep -E "${grep_pattern}" "${readme}" 2>/dev/null | 
grep -v "${grep_exclude}" || true)
+            if [ -n "${filtered}" ]; then
+                while IFS= read -r command; do
+                    command=$(echo "${command}" | tr -d '`' | sed 's/^#.*//')
+                    if [ -z "${command}" ]; then
+                        continue
+                    fi
+                    if declare -f TRANSFORM_COMMAND >/dev/null 2>&1; then
+                        command=$(TRANSFORM_COMMAND "${command}")
+                    fi
+                    echo -e "\e[33mChecking command from ${readme}:\e[0m 
${command}"
+                    echo ""
+                    set +e
+                    if [ "${cmd_timeout}" -gt 0 ] 2>/dev/null; then
+                        eval "portable_timeout ${cmd_timeout} ${command}"
+                        local test_exit_code=$?
+                        if [[ ${test_exit_code} -ne 0 && ${test_exit_code} -ne 
124 ]]; then
+                            EXAMPLES_EXIT_CODE=${test_exit_code}
+                        fi
+                    else
+                        eval "${command}"
+                        EXAMPLES_EXIT_CODE=$?
+                    fi
+                    set -e
+                    if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+                        echo ""
+                        echo -e "\e[31mCommand failed:\e[0m ${command}"
+                        echo ""
+                        break
+                    fi
+                    sleep 2
+                done <<< "${filtered}"
+            fi
+        else
+            run_readme_commands "${readme}" "${grep_pattern}" "${cmd_timeout}"
+        fi
+    done
+
+    cd "${ROOT_WORKDIR}"
+    stop_server
+
+    # --- TLS pass ---
+    if [ "${EXAMPLES_EXIT_CODE}" -eq 0 ] && [ "${SKIP_TLS}" = false ] && [ -n 
"${tls_grep_pattern}" ]; then
+        local has_tls=false
+        for readme in ${readme_files}; do
+            local readme_path="${readme}"
+            if [ "${workdir}" != "." ]; then
+                readme_path="${workdir}/${readme}"
+            fi
+            if [ -f "${readme_path}" ] && grep -qE "${tls_grep_pattern}" 
"${readme_path}" 2>/dev/null; then
+                has_tls=true
+                break
+            fi
+        done
+
+        if [ "${has_tls}" = true ]; then
+            echo ""
+            echo "=== Running ${lang} TLS examples ==="
+            echo ""
+
+            cleanup_server_state
+            # shellcheck disable=SC2086
+            start_tls_server ${server_extra_args}
+            wait_for_server_ready "${lang} TLS"
+
+            if [ "${workdir}" != "." ]; then
+                cd "${workdir}"
+            fi
+
+            for readme in ${readme_files}; do
+                if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+                    break
+                fi
+                run_readme_commands "${readme}" "${tls_grep_pattern}" 
"${cmd_timeout}"
+            done
+
+            cd "${ROOT_WORKDIR}"
+            stop_server
+        fi
+    fi
+
+    report_result "${EXAMPLES_EXIT_CODE}"
+    return "${EXAMPLES_EXIT_CODE}"
+}
+
+# ---------------------------------------------------------------------------
+# Per-language runners
+# ---------------------------------------------------------------------------
+
+# shellcheck disable=SC2329
+run_rust_examples() {
+    resolve_server_binary "${TARGET}"
+    resolve_cli_binary "${TARGET}"
+
+    # Transform: inject --target flag when cross-compiling
+    if [ -n "${TARGET}" ]; then
+        TRANSFORM_COMMAND() {
+            echo "$1" | sed "s|cargo r |cargo r --target ${TARGET} |g" | sed 
"s|cargo run |cargo run --target ${TARGET} |g"
+        }
+    else
+        unset -f TRANSFORM_COMMAND 2>/dev/null || true
+    fi
+
+    # First run CLI commands from root README.md (these match `cargo r --bin 
iggy -- `)
+    echo ""
+    echo "============================================================"
+    echo "  Running Rust CLI + example tests"
+    echo "============================================================"
+    echo ""
+
+    EXAMPLES_EXIT_CODE=0
+    cleanup_server_state
+    start_plain_server
+    wait_for_server_ready "Rust"
+
+    # CLI commands from root README (abbreviated `cargo r`, not `cargo run`)
+    run_readme_commands "README.md" '^\`cargo r --bin iggy -- '
+    if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+        cd "${ROOT_WORKDIR}"
+        stop_server
+        report_result "${EXAMPLES_EXIT_CODE}"
+        return "${EXAMPLES_EXIT_CODE}"

Review Comment:
   duplicated logic with run_csharp_examples (lines 414-502).  Could be 
addressed by making run_language_examples accept an optional "pre-flight" 
callback for CLI commands.



##########
scripts/run-examples-from-readme.sh:
##########
@@ -0,0 +1,545 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -euo pipefail
+
+# Unified script to run SDK examples from README.md files.
+# Usage: ./scripts/run-examples-from-readme.sh [OPTIONS]
+#
+#   --language LANG   Language to test: rust|go|node|python|java|csharp 
(default: all)
+#   --target TARGET   Cargo target architecture for the server binary
+#   --skip-tls        Skip TLS example tests
+#   --goos GOOS       Go OS target
+#   --goarch GOARCH   Go architecture target
+#   --csharpos OS     C# --os flag
+#   --csharparch ARCH C# --arch flag
+#
+# The script sources shared utilities from scripts/utils.sh, starts the iggy
+# server (built from source), parses example commands from each language's
+# README.md, and executes them. Non-TLS examples run first; then the server
+# is restarted with TLS for TLS-specific examples.
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# shellcheck source=scripts/utils.sh
+source "${SCRIPT_DIR}/utils.sh"
+
+ROOT_WORKDIR="$(pwd)"
+
+# ---------------------------------------------------------------------------
+# Argument parsing
+# ---------------------------------------------------------------------------
+LANGUAGE="all"
+TARGET=""
+SKIP_TLS=false
+GOOS=""
+GOARCH=""
+CSOS=""
+CSARCH=""
+
+while [[ $# -gt 0 ]]; do
+    case "$1" in
+        --language)   LANGUAGE="$2";  shift 2 ;;
+        --target)     TARGET="$2";    shift 2 ;;
+        --skip-tls)   SKIP_TLS=true;  shift   ;;
+        --goos)       GOOS="$2";      shift 2 ;;
+        --goarch)     GOARCH="$2";    shift 2 ;;
+        --csharpos)   CSOS="$2";      shift 2 ;;
+        --csharparch) CSARCH="$2";    shift 2 ;;
+        *)
+            echo "Unknown option: $1"
+            echo "Usage: $0 [--language LANG] [--target TARGET] [--skip-tls] 
[--goos GOOS] [--goarch GOARCH] [--csharpos OS] [--csharparch ARCH]"
+            exit 1
+            ;;
+    esac
+done
+
+# ---------------------------------------------------------------------------
+# Helpers
+# ---------------------------------------------------------------------------
+
+# Run a full non-TLS + TLS cycle for one language.
+# Arguments:
+#   $1 - language label (for logging)
+#   $2 - working directory (relative to repo root, or "." for root)
+#   $3 - space-separated list of README files (relative to workdir)
+#   $4 - grep pattern for non-TLS commands
+#   $5 - grep exclude pattern for non-TLS commands (empty = no exclude)
+#   $6 - grep pattern for TLS commands (empty = no TLS examples)
+#   $7 - per-command timeout in seconds (0 = no timeout)
+#   $8 - extra server args (e.g. "--fresh")
+# shellcheck disable=SC2329
+run_language_examples() {
+    local lang="$1"
+    local workdir="$2"
+    local readme_files="$3"
+    local grep_pattern="$4"
+    local grep_exclude="$5"
+    local tls_grep_pattern="$6"
+    local cmd_timeout="$7"
+    local server_extra_args="$8"
+
+    echo ""
+    echo "============================================================"
+    echo "  Running ${lang} examples"
+    echo "============================================================"
+    echo ""
+
+    EXAMPLES_EXIT_CODE=0
+
+    # --- Non-TLS pass ---
+    cleanup_server_state
+    # shellcheck disable=SC2086
+    start_plain_server ${server_extra_args}
+    wait_for_server_ready "${lang}"
+
+    if [ "${workdir}" != "." ]; then
+        cd "${workdir}"
+    fi
+
+    for readme in ${readme_files}; do
+        if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+            break
+        fi
+        if [ -n "${grep_exclude}" ]; then
+            # Build a combined pattern that filters out the exclude
+            local filtered
+            filtered=$(grep -E "${grep_pattern}" "${readme}" 2>/dev/null | 
grep -v "${grep_exclude}" || true)
+            if [ -n "${filtered}" ]; then
+                while IFS= read -r command; do
+                    command=$(echo "${command}" | tr -d '`' | sed 's/^#.*//')
+                    if [ -z "${command}" ]; then
+                        continue
+                    fi
+                    if declare -f TRANSFORM_COMMAND >/dev/null 2>&1; then
+                        command=$(TRANSFORM_COMMAND "${command}")
+                    fi
+                    echo -e "\e[33mChecking command from ${readme}:\e[0m 
${command}"
+                    echo ""
+                    set +e
+                    if [ "${cmd_timeout}" -gt 0 ] 2>/dev/null; then
+                        eval "portable_timeout ${cmd_timeout} ${command}"
+                        local test_exit_code=$?
+                        if [[ ${test_exit_code} -ne 0 && ${test_exit_code} -ne 
124 ]]; then
+                            EXAMPLES_EXIT_CODE=${test_exit_code}
+                        fi
+                    else
+                        eval "${command}"
+                        EXAMPLES_EXIT_CODE=$?
+                    fi
+                    set -e
+                    if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+                        echo ""
+                        echo -e "\e[31mCommand failed:\e[0m ${command}"
+                        echo ""
+                        break
+                    fi
+                    sleep 2
+                done <<< "${filtered}"
+            fi
+        else
+            run_readme_commands "${readme}" "${grep_pattern}" "${cmd_timeout}"
+        fi
+    done
+
+    cd "${ROOT_WORKDIR}"
+    stop_server
+
+    # --- TLS pass ---
+    if [ "${EXAMPLES_EXIT_CODE}" -eq 0 ] && [ "${SKIP_TLS}" = false ] && [ -n 
"${tls_grep_pattern}" ]; then
+        local has_tls=false
+        for readme in ${readme_files}; do
+            local readme_path="${readme}"
+            if [ "${workdir}" != "." ]; then
+                readme_path="${workdir}/${readme}"
+            fi
+            if [ -f "${readme_path}" ] && grep -qE "${tls_grep_pattern}" 
"${readme_path}" 2>/dev/null; then
+                has_tls=true
+                break
+            fi
+        done
+
+        if [ "${has_tls}" = true ]; then
+            echo ""
+            echo "=== Running ${lang} TLS examples ==="
+            echo ""
+
+            cleanup_server_state
+            # shellcheck disable=SC2086
+            start_tls_server ${server_extra_args}
+            wait_for_server_ready "${lang} TLS"
+
+            if [ "${workdir}" != "." ]; then
+                cd "${workdir}"
+            fi
+
+            for readme in ${readme_files}; do
+                if [ "${EXAMPLES_EXIT_CODE}" -ne 0 ]; then
+                    break
+                fi
+                run_readme_commands "${readme}" "${tls_grep_pattern}" 
"${cmd_timeout}"
+            done
+
+            cd "${ROOT_WORKDIR}"
+            stop_server
+        fi
+    fi
+
+    report_result "${EXAMPLES_EXIT_CODE}"
+    return "${EXAMPLES_EXIT_CODE}"
+}
+
+# ---------------------------------------------------------------------------
+# Per-language runners
+# ---------------------------------------------------------------------------
+
+# shellcheck disable=SC2329
+run_rust_examples() {
+    resolve_server_binary "${TARGET}"
+    resolve_cli_binary "${TARGET}"
+
+    # Transform: inject --target flag when cross-compiling
+    if [ -n "${TARGET}" ]; then
+        TRANSFORM_COMMAND() {

Review Comment:
   run_rust_examples defines TRANSFORM_COMMAND as a global function and cleans 
it up at line 297. But if the function returns early at line 243 (return 
"${EXAMPLES_EXIT_CODE}"), the cleanup at 297 is never reached. In --language 
all mode, this leaks the Rust cross-compile transform into the next language's 
execution.
   
   use trap or move unset into run_one after each language call



##########
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
+}

Review Comment:
   i'm not a fan of sleeping. please add actual verification whether givern PID 
has actually exited. (this is preexisting issue). please send sigterm, then 
wait for 2s via timeout wait/waitpid, then sigkill and fail test. does that 
make sense?



-- 
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]

Reply via email to