Skip to content

Commit

Permalink
Add integration flaky error test script. (#545)
Browse files Browse the repository at this point in the history
Signed-off-by: xuezhaojun <[email protected]>
  • Loading branch information
xuezhaojun authored Jul 4, 2024
1 parent 2af3a30 commit 2857778
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
55 changes: 55 additions & 0 deletions hack/e2e_flaky_error_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Check if there are enough arguments
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <RUN_TIMES> [KlusterletDeployMode]"
exit 1
fi

# Read command line arguments
RUN_TIMES=$1
BUILD_IMAGES=${2:-yes} # Default to 'yes' if the third argument is not provided
KLUSTERLET_DEPLOY_MODE=${3:-Default} # Use Default if the second argument is not provided

# Conditionally build images for testing
if [ "$BUILD_IMAGES" = "yes" ]; then
make images build
fi

# Create the directory to store test results with timestamp
mkdir -p "_output/flaky-error-test"

# Loop to run tests
for (( i=1; i<=RUN_TIMES; i++ ))
do
# Create a kind cluster
kind create cluster --name=e2e

# Load test images into the kind cluster
kind load docker-image --name=e2e quay.io/open-cluster-management/registration-operator:$IMAGE_TAG
kind load docker-image --name=e2e quay.io/open-cluster-management/registration:$IMAGE_TAG
kind load docker-image --name=e2e quay.io/open-cluster-management/work:$IMAGE_TAG
kind load docker-image --name=e2e quay.io/open-cluster-management/placement:$IMAGE_TAG
kind load docker-image --name=e2e quay.io/open-cluster-management/addon-manager:$IMAGE_TAG

echo "Running e2e test iteration $((i+1))/$RUN_TIMES with KlusterletDeployMode=$KLUSTERLET_DEPLOY_MODE"
test_output=$(IMAGE_TAG=$IMAGE_TAG KLUSTERLET_DEPLOY_MODE=$KLUSTERLET_DEPLOY_MODE make test-e2e 2>&1)
test_exit_code=$?

# Determine test result and update the respective list
if [ $test_exit_code -eq 0 ]; then
echo "Test $i passed"
else
echo "Test $i failed"
timestamp=$(date +"%Y%m%d-%H%M%S")
output_file="_output/flaky-error-test/e2e_test_$timestamp_${i}.output"
echo "$test_output" > "$output_file"
echo "Exiting due to failure."
exit 1
fi

# If the test is successful, delete clusters
kind delete cluster --name=e2e
done

echo "All tests completed successfully."
34 changes: 34 additions & 0 deletions hack/integration_flaky_error_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Get the number of tests to run from the first command line argument
n=$1

# Check if the test count was provided
if [[ -z "$n" ]]; then
echo "Usage: $0 <number-of-tests>"
exit 1
fi

# Create the directory to store test results with timestamp
mkdir -p "_output/flaky-error-test"

# Loop to run the tests n times
for (( i=1; i<=n; i++ ))
do
echo "Running test $i of $n..."
# Run the test command and capture the output
test_output=$(make test-integration 2>&1)
test_exit_code=$?

# Determine test result and update the respective list
if [ $test_exit_code -eq 0 ]; then
echo "Test $i passed"
else
echo "Test $i failed"
timestamp=$(date +"%Y%m%d-%H%M%S")
output_file="_output/flaky-error-test/integration_test_$timestamp_${i}.output"
echo "$test_output" > "$output_file"
echo "Test $i result stored in $output_file"
exit 1
fi
done

0 comments on commit 2857778

Please sign in to comment.