|
1 | 1 | #!/bin/bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -# Debug: Show bash version and options in CI |
5 | | -if [[ -n "${CI:-}" ]]; then |
6 | | - echo "[DEBUG] Bash version: $BASH_VERSION" >&2 |
7 | | - echo "[DEBUG] Bash options: $-" >&2 |
8 | | -fi |
9 | | - |
10 | 4 | # Troupe Multi-Node Test Runner - Refactored Version |
11 | 5 | # Orchestrates multi-node tests with proper cleanup and output synchronization |
12 | 6 | # |
@@ -152,7 +146,6 @@ cleanup() { |
152 | 146 | # CRITICAL: Capture the original exit code immediately |
153 | 147 | # This must be the FIRST command in cleanup to preserve test results |
154 | 148 | local exit_code=$? |
155 | | - echo "[DEBUG] Cleanup called with exit code: $exit_code" >&2 |
156 | 149 | log "Cleaning up test processes (exit code: $exit_code)..." |
157 | 150 |
|
158 | 151 | local cleaned_count=0 |
@@ -317,7 +310,6 @@ cleanup() { |
317 | 310 | # CRITICAL: Exit with the original exit code from the test, not from cleanup |
318 | 311 | # Without this, the script would exit with the status of the last cleanup command |
319 | 312 | # This is why tests were "failing" in CI even though they succeeded |
320 | | - echo "[DEBUG] Exiting cleanup with code: $exit_code" >&2 |
321 | 313 | exit $exit_code |
322 | 314 | } |
323 | 315 |
|
@@ -632,10 +624,11 @@ run_node() { |
632 | 624 | local node_index="$2" |
633 | 625 | local test_dir="$3" |
634 | 626 | local output_dir="$4" |
635 | | - |
| 627 | + local in_parallel="${5:-false}" # New parameter to indicate parallel mode |
| 628 | + |
636 | 629 | local node_config |
637 | 630 | node_config=$(jq -r ".nodes[$node_index]" "$config_file") |
638 | | - |
| 631 | + |
639 | 632 | local node_id script port start_delay expected_exit_code extra_argv |
640 | 633 | node_id=$(echo "$node_config" | jq -r '.id') |
641 | 634 | script=$(echo "$node_config" | jq -r '.script') |
@@ -762,14 +755,23 @@ run_node() { |
762 | 755 | log "Node $node_id timed out as expected after ${scaled_timeout}s" |
763 | 756 | else |
764 | 757 | display_node_error "$node_id" "timeout" "$scaled_timeout" "$expected_exit_code" "$output_file" "$error_file" "$timeout_val" |
765 | | - error "Node $node_id timed out unexpectedly" |
| 758 | + if [[ "$in_parallel" == "true" ]]; then |
| 759 | + return 1 # Return error code instead of exiting in parallel mode |
| 760 | + else |
| 761 | + error "Node $node_id timed out unexpectedly" |
| 762 | + fi |
766 | 763 | fi |
767 | 764 | elif [[ "$actual_exit_code" != "$expected_exit_code" ]]; then |
768 | 765 | display_node_error "$node_id" "exit_code" "$actual_exit_code" "$expected_exit_code" "$output_file" "$error_file" |
769 | | - error "Node $node_id exited with code $actual_exit_code, expected $expected_exit_code" |
| 766 | + if [[ "$in_parallel" == "true" ]]; then |
| 767 | + return 1 # Return error code instead of exiting in parallel mode |
| 768 | + else |
| 769 | + error "Node $node_id exited with code $actual_exit_code, expected $expected_exit_code" |
| 770 | + fi |
770 | 771 | fi |
771 | 772 |
|
772 | 773 | log "Node $node_id completed successfully (exit code: $actual_exit_code)" |
| 774 | + return 0 # Explicitly return success |
773 | 775 | } |
774 | 776 |
|
775 | 777 | merge_outputs() { |
@@ -864,26 +866,26 @@ run_test() { |
864 | 866 | # Start all nodes simultaneously |
865 | 867 | local node_pids=() |
866 | 868 | for ((i=0; i<node_count; i++)); do |
867 | | - run_node "$config_file" "$i" "$test_dir" "$output_dir" & |
| 869 | + run_node "$config_file" "$i" "$test_dir" "$output_dir" "true" & |
868 | 870 | node_pids+=($!) |
869 | 871 | done |
870 | | - |
| 872 | + |
871 | 873 | # Wait for all nodes |
872 | 874 | local failed=false |
873 | 875 | for pid in "${node_pids[@]}"; do |
874 | 876 | if ! wait "$pid"; then |
875 | 877 | failed=true |
876 | 878 | fi |
877 | 879 | done |
878 | | - |
| 880 | + |
879 | 881 | if [[ "$failed" == "true" ]]; then |
880 | 882 | error "One or more nodes failed" |
881 | 883 | fi |
882 | 884 | ;; |
883 | 885 | "sequential") |
884 | 886 | # Start nodes one after another |
885 | 887 | for ((i=0; i<node_count; i++)); do |
886 | | - run_node "$config_file" "$i" "$test_dir" "$output_dir" |
| 888 | + run_node "$config_file" "$i" "$test_dir" "$output_dir" "false" |
887 | 889 | done |
888 | 890 | ;; |
889 | 891 | *) |
|
0 commit comments