Skip to content

Commit e61db0e

Browse files
committed
🚧 Silent Push Sync flow test
1 parent 86d9ff3 commit e61db0e

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed

tests/business-critical-integration/scripts/run-tests.sh

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,22 +469,45 @@ clear_screenshots_directory() {
469469
# MARK: - Push Notification Support
470470

471471
setup_push_monitoring() {
472-
if [[ "$CI" == "1" ]]; then
472+
# Check both CI env var and config.json ciMode setting
473+
local CI_MODE="$CI"
474+
if [[ -f "$LOCAL_CONFIG_FILE" ]] && command -v jq &> /dev/null; then
475+
local CONFIG_CI_MODE=$(jq -r '.testing.ciMode // false' "$LOCAL_CONFIG_FILE")
476+
if [[ "$CONFIG_CI_MODE" == "true" ]]; then
477+
CI_MODE="1"
478+
echo_info "🔍 CI mode detected from config.json (ciMode: true)"
479+
fi
480+
fi
481+
482+
if [[ "$CI_MODE" == "1" ]]; then
473483
echo_info "🤖 Setting up push notification monitoring for CI environment"
474484

475485
# Create push queue directory
476486
local PUSH_QUEUE_DIR="/tmp/push_queue"
477487
mkdir -p "$PUSH_QUEUE_DIR"
478488

489+
# Create log file for push monitor
490+
local PUSH_MONITOR_LOG="$LOGS_DIR/push_monitor.log"
491+
479492
echo_info "📁 Push queue directory: $PUSH_QUEUE_DIR"
493+
echo_info "📝 Push monitor log: $PUSH_MONITOR_LOG"
480494
echo_info "🔍 Starting background push monitor..."
481495

482-
# Start background push monitor
483-
start_push_monitor "$PUSH_QUEUE_DIR" &
496+
# Start background push monitor with logging
497+
start_push_monitor "$PUSH_QUEUE_DIR" > "$PUSH_MONITOR_LOG" 2>&1 &
484498
local MONITOR_PID=$!
485499
echo "$MONITOR_PID" > "/tmp/push_monitor.pid"
486500

487-
echo_info "⚡ Push monitor started with PID: $MONITOR_PID"
501+
# Give it a moment to start
502+
sleep 0.5
503+
504+
# Verify it's running
505+
if ps -p "$MONITOR_PID" > /dev/null 2>&1; then
506+
echo_info "⚡ Push monitor started with PID: $MONITOR_PID"
507+
else
508+
echo_error "❌ Push monitor failed to start!"
509+
cat "$PUSH_MONITOR_LOG"
510+
fi
488511
else
489512
echo_info "📱 Local environment - push monitoring not needed"
490513
fi
@@ -493,35 +516,36 @@ setup_push_monitoring() {
493516
start_push_monitor() {
494517
local PUSH_QUEUE_DIR="$1"
495518

496-
echo_info "🔄 Push monitor started - watching: $PUSH_QUEUE_DIR"
519+
# Use plain echo since this runs in background process
520+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 🔄 Push monitor started - watching: $PUSH_QUEUE_DIR"
497521

498522
while true; do
499523
# Look for new command files
500524
for COMMAND_FILE in "$PUSH_QUEUE_DIR"/command_*.txt; do
501525
[[ -f "$COMMAND_FILE" ]] || continue
502526

503-
echo_info "📋 Found command file: $COMMAND_FILE"
527+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 📋 Found command file: $COMMAND_FILE"
504528

505529
# Read and execute the command
506530
local COMMAND=$(cat "$COMMAND_FILE" 2>/dev/null)
507531
if [[ -n "$COMMAND" ]]; then
508-
echo_info "🚀 Executing push command: $COMMAND"
532+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 🚀 Executing push command: $COMMAND"
509533

510534
# Execute the xcrun simctl command
511-
eval "$COMMAND"
535+
eval "$COMMAND" 2>&1
512536
local EXIT_CODE=$?
513537

514538
if [[ $EXIT_CODE -eq 0 ]]; then
515-
echo_info "✅ Push notification sent successfully"
539+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ✅ Push notification sent successfully"
516540
else
517-
echo_error "❌ Push notification failed with exit code: $EXIT_CODE"
541+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ❌ Push notification failed with exit code: $EXIT_CODE"
518542
fi
519543

520544
# Remove the command file after processing
521545
rm -f "$COMMAND_FILE"
522-
echo_info "🗑️ Cleaned up command file: $COMMAND_FILE"
546+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 🗑️ Cleaned up command file: $COMMAND_FILE"
523547
else
524-
echo_warning "⚠️ Empty command file: $COMMAND_FILE"
548+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ⚠️ Empty command file: $COMMAND_FILE"
525549
rm -f "$COMMAND_FILE"
526550
fi
527551
done
@@ -536,6 +560,31 @@ cleanup_push_monitoring() {
536560
local MONITOR_PID=$(cat /tmp/push_monitor.pid)
537561
echo_info "🛑 Stopping push monitor (PID: $MONITOR_PID)"
538562

563+
# Check if monitor is still running
564+
if ps -p "$MONITOR_PID" > /dev/null 2>&1; then
565+
echo_info "✓ Push monitor is still running"
566+
else
567+
echo_warning "⚠️ Push monitor process not found - may have crashed!"
568+
fi
569+
570+
# Show push monitor logs if they exist
571+
local PUSH_MONITOR_LOG="$LOGS_DIR/push_monitor.log"
572+
if [[ -f "$PUSH_MONITOR_LOG" ]]; then
573+
echo_info "📋 Push monitor activity:"
574+
cat "$PUSH_MONITOR_LOG"
575+
else
576+
echo_warning "⚠️ Push monitor log not found: $PUSH_MONITOR_LOG"
577+
fi
578+
579+
# Check for unprocessed files in the queue
580+
if [[ -d "/tmp/push_queue" ]]; then
581+
local UNPROCESSED_COUNT=$(find /tmp/push_queue -type f | wc -l | tr -d ' ')
582+
if [[ $UNPROCESSED_COUNT -gt 0 ]]; then
583+
echo_warning "⚠️ Found $UNPROCESSED_COUNT unprocessed files in push queue:"
584+
ls -la /tmp/push_queue/
585+
fi
586+
fi
587+
539588
kill "$MONITOR_PID" 2>/dev/null || true
540589
rm -f "/tmp/push_monitor.pid"
541590

0 commit comments

Comments
 (0)