Skip to content

Commit 53c1607

Browse files
fixes
1 parent cdb3426 commit 53c1607

3 files changed

Lines changed: 81 additions & 26 deletions

File tree

src/test/scripts/generate-blocks.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@ set -euo pipefail
33

44
SIM_URL="${SIM_URL:-http://localhost:8085}"
55
BLOCKS="${BLOCKS:-10}"
6+
TIMEOUT_SEC="${TIMEOUT_SEC:-120}"
7+
8+
echo "[generate-blocks] Waiting for simulator at ${SIM_URL} (timeout ${TIMEOUT_SEC}s)"
9+
start=$(date +%s)
10+
while true; do
11+
# Try a cheap HEAD on the base URL or GET on a likely health path
12+
if curl -s -o /dev/null -I "${SIM_URL}" || curl -s -o /dev/null "${SIM_URL}/network/status"; then
13+
break
14+
fi
15+
now=$(date +%s)
16+
if [ $((now-start)) -gt ${TIMEOUT_SEC} ]; then
17+
echo "[generate-blocks] Simulator not reachable at ${SIM_URL} within timeout" >&2
18+
exit 1
19+
fi
20+
sleep 2
21+
done
622

723
echo "[generate-blocks] Generating ${BLOCKS} blocks at ${SIM_URL}"
824
curl --fail --silent --show-error --request POST \
925
--url "${SIM_URL}/simulator/generate-blocks/${BLOCKS}" \
1026
--header 'Content-Type: application/json'
1127
echo
12-

src/test/scripts/setup-rabbit-state.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ RABBIT_MGMT_PORT="${RABBIT_MGMT_PORT:-15672}"
77
RABBIT_USER="${RABBIT_USER:-guest}"
88
RABBIT_PASS="${RABBIT_PASS:-guest}"
99
EXCHANGE_NAME="${EXCHANGE_NAME:-state_accesses}"
10+
EXCHANGE_TYPE="${EXCHANGE_TYPE:-fanout}"
1011
QUEUE_NAME="${QUEUE_NAME:-state_accesses_test}"
1112
ROUTING_KEY="${ROUTING_KEY:-#}"
1213

@@ -24,13 +25,13 @@ http_code() {
2425
curl -s -o /dev/null -w "%{http_code}" -u "${RABBIT_USER}:${RABBIT_PASS}" "$1"
2526
}
2627

27-
echo "[rabbit-setup] Ensuring exchange '${EXCHANGE_NAME}' exists"
28+
echo "[rabbit-setup] Ensuring exchange '${EXCHANGE_NAME}' exists (type='${EXCHANGE_TYPE}')"
2829
ex_code=$(http_code "${base}/exchanges/%2f/${EXCHANGE_NAME}")
2930
if [ "${ex_code}" != "200" ]; then
3031
out=$(curl -s -u "${RABBIT_USER}:${RABBIT_PASS}" -H "content-type: application/json" \
3132
-w "\n%{http_code}" \
3233
-X PUT "${base}/exchanges/%2f/${EXCHANGE_NAME}" \
33-
-d '{"type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}}')
34+
-d '{"type":"'"${EXCHANGE_TYPE}"'","durable":true,"auto_delete":false,"internal":false,"arguments":{}}')
3435
code=$(echo "$out" | tail -n1)
3536
if [ "$code" != "201" ] && [ "$code" != "204" ]; then
3637
echo "[rabbit-setup] Failed to create exchange, status: $code" >&2
@@ -77,4 +78,3 @@ else
7778
fi
7879

7980
echo "[rabbit-setup] Done"
80-

src/test/scripts/setup-simulator-and-notifier.sh

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ CHAIN_GO_COMMIT="757f2de643d3d69494179cd899d92b31edfbb64a" # github.com/m
2020
CHAIN_CORE_GO_COMMIT="60b4de5d3d1bb3f2a34c764f8cf353c5af8c3194" # github.com/multiversx/mx-chain-core-go
2121

2222
# Endpoint check
23-
VERIFY_URL="${VERIFY_URL:-http://localhost:8085/network/status/0}"
23+
# One or more candidate health URLs for the simulator; the first 200 wins
24+
# (different simulator versions may expose different status routes)
25+
VERIFY_URLS=(
26+
"${VERIFY_URL:-http://localhost:8085/network/status/0}"
27+
"http://localhost:8085/network/status"
28+
"http://localhost:8085/simulator/health"
29+
"http://localhost:8085/health"
30+
)
2431
VERIFY_TIMEOUT_SEC="${VERIFY_TIMEOUT_SEC:-120}"
2532
LOG_SNIFF_INTERVAL_SEC="${LOG_SNIFF_INTERVAL_SEC:-10}"
2633

@@ -208,6 +215,26 @@ patch_notifier_redis_hosts() {
208215
"$toml_path" || true
209216
}
210217

218+
# Optionally patch the WebSocketConnector path/host/port if provided via env
219+
patch_notifier_ws_endpoint() {
220+
local notifier_dir="$1"
221+
local toml_path="$notifier_dir/cmd/notifier/config/config.toml"
222+
local ws_path="${NOTIFIER_WS_PATH:-}"
223+
local ws_host="${NOTIFIER_WS_HOST:-127.0.0.1}"
224+
local ws_port="${NOTIFIER_WS_PORT:-22111}"
225+
if [[ ! -f "$toml_path" ]]; then
226+
err "Notifier config not found: $toml_path"
227+
exit 1
228+
fi
229+
if [[ -n "$ws_path" ]]; then
230+
log "Patching WebSocketConnector path to '${ws_path}', host to '${ws_host}', port to '${ws_port}' in $toml_path"
231+
sed -i.bak \
232+
-e "s#^\([[:space:]]*Path[[:space:]]*=\).*#\1 \"${ws_path}\"#" \
233+
-e "s#^\([[:space:]]*Url[[:space:]]*=\).*#\1 \"${ws_host}:${ws_port}\"#" \
234+
"$toml_path" || true
235+
fi
236+
}
237+
211238
start_notifier() {
212239
local notifier_dir="$1"
213240
pushd "$notifier_dir" >/dev/null
@@ -234,32 +261,31 @@ start_chainsimulator() {
234261
echo "$pid"
235262
}
236263

237-
wait_for_http_200() {
238-
local url="$1" timeout_sec="$2"
264+
wait_for_http_200_any() {
265+
local -n urls_ref=$1
266+
local timeout_sec="$2"
239267
local chain_log="$3" notifier_log="$4"
240-
log "Waiting for 200 from $url (timeout ${timeout_sec}s)"
241-
local start_ts now code last_log_print=0 iter=0 tmp body_preview
268+
local start_ts now code last_log_print=0 tmp body_preview url
242269
start_ts=$(date +%s)
270+
log "Waiting for simulator to be ready on any of: ${urls_ref[*]} (timeout ${timeout_sec}s)"
243271
while true; do
244-
iter=$((iter+1))
245-
tmp=$(mktemp)
246-
code=$(curl -s -o "$tmp" -w "%{http_code}" "$url" || true)
247-
if [[ "$code" == "200" ]]; then
248-
log "Received HTTP 200 from $url"
249-
# Print a short preview of the response body
250-
body_preview=$(head -c 2000 "$tmp" | tr -d '\r')
251-
printf "[+] %s\n%s\n" "Status body preview:" "$body_preview" >&2
272+
for url in "${urls_ref[@]}"; do
273+
tmp=$(mktemp)
274+
code=$(curl -s -o "$tmp" -w "%{http_code}" "$url" || true)
275+
if [[ "$code" == "200" ]]; then
276+
log "Received HTTP 200 from $url"
277+
body_preview=$(head -c 2000 "$tmp" | tr -d '\r')
278+
printf "[+] %s\n%s\n" "Status body preview:" "$body_preview" >&2
279+
rm -f "$tmp"
280+
return 0
281+
fi
252282
rm -f "$tmp"
253-
return 0
254-
fi
283+
done
255284

256-
# Periodically show the non-200 response and some logs
257285
now=$(date +%s)
258286
if (( now - last_log_print >= LOG_SNIFF_INTERVAL_SEC )); then
259287
last_log_print=$now
260-
body_preview=$(head -c 2000 "$tmp" | tr -d '\r')
261-
printf "[!] %s %s\n" "Non-200 status:" "$code" >&2
262-
printf "[!] %s\n%s\n" "Response body (preview):" "$body_preview" >&2
288+
printf "[!] %s\n" "Simulator not ready yet (no 200 from any URL)" >&2
263289
if [[ -f "$chain_log" ]]; then
264290
printf "[!] %s\n" "Tail of chainsimulator logs:" >&2
265291
tail -n 60 "$chain_log" >&2 || true
@@ -269,10 +295,9 @@ wait_for_http_200() {
269295
tail -n 40 "$notifier_log" >&2 || true
270296
fi
271297
fi
272-
rm -f "$tmp"
273298

274299
if (( now - start_ts > timeout_sec )); then
275-
err "Timeout waiting for HTTP 200 from $url (last code: $code)"
300+
err "Timeout waiting for HTTP 200 from any simulator status URL"
276301
return 1
277302
fi
278303
sleep 2
@@ -301,6 +326,7 @@ main() {
301326
# 7) Enable WebSocketConnector in notifier config
302327
enable_ws_connector "$NOTIFIER_DIR"
303328
patch_notifier_redis_hosts "$NOTIFIER_DIR"
329+
patch_notifier_ws_endpoint "$NOTIFIER_DIR"
304330

305331
# 8) Ensure Redis + Sentinel are running locally for notifier
306332
start_redis_and_sentinel || {
@@ -311,14 +337,28 @@ main() {
311337
notifier_pid=$(start_notifier "$NOTIFIER_DIR")
312338
log "Notifier PID: $notifier_pid"
313339

340+
# 9.1) Wait for Notifier WS port to be open before starting simulator
341+
local notifier_host="127.0.0.1" notifier_port=22111
342+
log "Waiting for Notifier WS ${notifier_host}:${notifier_port} to accept connections..."
343+
for i in {1..60}; do
344+
if port_open "$notifier_host" "$notifier_port"; then
345+
log "Notifier WS is up"
346+
break
347+
fi
348+
sleep 1
349+
done
350+
if ! port_open "$notifier_host" "$notifier_port"; then
351+
err "Notifier WS did not open on ${notifier_host}:${notifier_port} in time"
352+
fi
353+
314354
# 10) Start chain simulator next
315355
chainsim_pid=$(start_chainsimulator "$SIM_DIR")
316356
log "ChainSimulator PID: $chainsim_pid"
317357

318358
# 11) Verify HTTP 200 after both are up
319359
local chain_log="$SIM_DIR/cmd/chainsimulator/chainsimulator.out"
320360
local notifier_log="$NOTIFIER_DIR/notifier.out"
321-
if ! wait_for_http_200 "$VERIFY_URL" "$VERIFY_TIMEOUT_SEC" "$chain_log" "$notifier_log"; then
361+
if ! wait_for_http_200_any VERIFY_URLS "$VERIFY_TIMEOUT_SEC" "$chain_log" "$notifier_log"; then
322362
err "Verification failed. See $NOTIFIER_DIR/notifier.out for logs."
323363
exit 1
324364
fi

0 commit comments

Comments
 (0)