From d02b50d311442450709ac6327d440dafd67a5705 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Tue, 21 Oct 2025 11:45:07 +0200 Subject: [PATCH 1/2] [CI] Add retries to avoid failing because of flakey network issues --- scripts/run_examples.sh | 68 +++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/scripts/run_examples.sh b/scripts/run_examples.sh index 3ef2f9e..a27361d 100755 --- a/scripts/run_examples.sh +++ b/scripts/run_examples.sh @@ -1,5 +1,34 @@ #!/bin/bash +# Default retry count +RETRY_COUNT=3 + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + --no-extra-dep) + NO_EXTRA_DEP=true + shift + ;; + --retry-count) + RETRY_COUNT="$2" + shift 2 + ;; + --help) + echo "Usage: $0 [--no-extra-dep] [--retry-count N]" + echo " --no-extra-dep: Exclude files that require extra dependencies" + echo " --retry-count N: Number of retries for each test (default: 3)" + echo " --help: Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done + # List of files to exclude exclude_files=( "examples/mistral/chat/chatbot_with_streaming.py" @@ -13,8 +42,8 @@ exclude_files=( "examples/mistral/agents/async_conversation_run_mcp_remote.py" ) -# Check if the first argument is "no-extra-dep" then remove all the files that require the extra dependencies -if [ "$1" = "--no-extra-dep" ]; then +# Check if the no-extra-dep flag is set +if [ "$NO_EXTRA_DEP" = true ]; then # Add more files to the exclude list exclude_files+=( "examples/mistral/agents/async_conversation_run_mcp_remote.py" @@ -25,19 +54,40 @@ fi failed=0 -for file in examples/mistral/**/*.py; do - # Check if the file is not in the exclude list - if [ -f "$file" ] && [[ ! " ${exclude_files[@]} " =~ " $file " ]]; then - echo "Running $file" +# Function to run a test with retries +run_test_with_retries() { + local file="$1" + local attempt=1 + + while [ $attempt -le $RETRY_COUNT ]; do + echo "Running $file (attempt $attempt/$RETRY_COUNT)" + # Run the script and capture the exit status - if python3 "$file" > /dev/null; then + if python3 "$file" > /dev/null 2>&1; then echo "Success" + return 0 else - echo "Failed" + if [ $attempt -lt $RETRY_COUNT ]; then + echo "Failed (attempt $attempt/$RETRY_COUNT), retrying..." + sleep 1 # Brief pause before retry + else + echo "Failed after $RETRY_COUNT attempts" + return 1 + fi + fi + + attempt=$((attempt + 1)) + done +} + +for file in examples/mistral/**/*.py; do + # Check if the file is not in the exclude list + if [ -f "$file" ] && [[ ! " ${exclude_files[@]} " =~ " $file " ]]; then + if ! run_test_with_retries "$file"; then failed=1 fi else - echo "Skipped $file" + echo "Skipped $file" fi done From 05d6bf25de1570d9f62c1f289f1f9e1eff6a5b62 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Tue, 21 Oct 2025 11:54:20 +0200 Subject: [PATCH 2/2] Print each retry error if all retries failed --- scripts/run_examples.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/run_examples.sh b/scripts/run_examples.sh index a27361d..d9ff43b 100755 --- a/scripts/run_examples.sh +++ b/scripts/run_examples.sh @@ -58,20 +58,32 @@ failed=0 run_test_with_retries() { local file="$1" local attempt=1 + local error_outputs=() while [ $attempt -le $RETRY_COUNT ]; do echo "Running $file (attempt $attempt/$RETRY_COUNT)" - # Run the script and capture the exit status - if python3 "$file" > /dev/null 2>&1; then + # Run the script and capture both exit status and error output + local current_output=$(python3 "$file" 2>&1) + local exit_code=$? + + if [ $exit_code -eq 0 ]; then echo "Success" return 0 else + # Store the error output from this attempt + error_outputs+=("Attempt $attempt: $current_output") + if [ $attempt -lt $RETRY_COUNT ]; then echo "Failed (attempt $attempt/$RETRY_COUNT), retrying..." sleep 1 # Brief pause before retry else echo "Failed after $RETRY_COUNT attempts" + echo "Error outputs from all attempts:" + for error_output in "${error_outputs[@]}"; do + echo "$error_output" + echo "---" + done return 1 fi fi