@@ -20,7 +20,14 @@ CHAIN_GO_COMMIT="757f2de643d3d69494179cd899d92b31edfbb64a" # github.com/m
2020CHAIN_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+ )
2431VERIFY_TIMEOUT_SEC=" ${VERIFY_TIMEOUT_SEC:- 120} "
2532LOG_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+
211238start_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