diff --git a/testing/static/scripts/ping-test.sh b/testing/static/scripts/ping-test.sh index 2140a6e..de0ede1 100755 --- a/testing/static/scripts/ping-test.sh +++ b/testing/static/scripts/ping-test.sh @@ -27,6 +27,9 @@ fi # shellcheck source=../generated-configs/npubs.env source "$ENV_FILE" +NPUBS=("$NPUB_A" "$NPUB_B" "$NPUB_C" "$NPUB_D" "$NPUB_E") +LABELS=(A B C D E) + ping_test() { local from="$1" local to_npub="$2" @@ -36,7 +39,8 @@ ping_test() { local output if output=$(docker exec "fips-$from" ping6 -c "$COUNT" -W "$TIMEOUT" "${to_npub}.fips" 2>&1); then # Extract round-trip time from ping output - local rtt=$(echo "$output" | grep -oE 'time=[0-9.]+' | cut -d= -f2) + local rtt + rtt=$(echo "$output" | grep -oE 'time=[0-9.]+' | cut -d= -f2) if [ -n "$rtt" ]; then echo "OK (${rtt}ms)" else @@ -49,18 +53,67 @@ ping_test() { fi } +# Quietly ping all pairs to check FSP-level convergence. +ping_all_quiet() { + PASSED=0 + FAILED=0 + local n=${#LABELS[@]} + for ((i=0; i/dev/null 2>&1; then + PASSED=$((PASSED + 1)) + else + FAILED=$((FAILED + 1)) + fi + done + done +} + +# Wait until all ping pairs succeed or timeout. +wait_for_full_connectivity() { + local timeout="${1:-30}" + local start_secs=$SECONDS + + while (( SECONDS - start_secs < timeout )); do + ping_all_quiet + if [ "$FAILED" -eq 0 ]; then + echo " All $PASSED pairs reachable after $((SECONDS - start_secs))s" + return 0 + fi + sleep 1 + done + echo " TIMEOUT: $PASSED passed, $FAILED failed after ${timeout}s" + return 1 +} + echo "=== FIPS Ping Test ($PROFILE topology) ===" echo "" -# Wait for nodes to converge — peers + discovery propagation +# Wait for nodes to converge — all nodes must reach expected peer counts. echo "Waiting for mesh convergence..." if [ "$PROFILE" = "chain" ]; then - wait_for_peers fips-node-b 2 15 || true -else - wait_for_peers fips-node-a 2 15 || true + # Chain: A-B-C-D-E, each interior node has 2 peers, endpoints have 1 + wait_for_peers fips-node-a 1 20 || true + wait_for_peers fips-node-b 2 20 || true + wait_for_peers fips-node-c 2 20 || true + wait_for_peers fips-node-d 2 20 || true + wait_for_peers fips-node-e 1 20 || true +elif [ "$PROFILE" = "mesh" ] || [ "$PROFILE" = "mesh-public" ]; then + # Mesh: check all nodes reach their configured peer counts + wait_for_peers fips-node-a 2 20 || true + wait_for_peers fips-node-b 1 20 || true + wait_for_peers fips-node-c 3 20 || true + wait_for_peers fips-node-d 3 20 || true + wait_for_peers fips-node-e 3 20 || true fi -# Allow extra time for discovery to propagate across the mesh -sleep 3 +# Wait for FSP-level connectivity (discovery + session establishment) +wait_for_full_connectivity 30 || true + +# Reset counters for the actual test +PASSED=0 +FAILED=0 if [ "$PROFILE" = "mesh" ] || [ "$PROFILE" = "mesh-public" ]; then # Sparse mesh topology: A-B, B-C, C-D, D-E, E-A, A-D