Admin: Simplify dependency test (#5827)

This commit is contained in:
Bert Blommers 2023-01-07 22:54:00 +00:00 committed by GitHub
parent 27a2e42d9b
commit 4165aa8ae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 48 deletions

View File

@ -6,12 +6,23 @@ on:
- cron: '0 0 * * *' # every day at midnight - cron: '0 0 * * *' # every day at midnight
jobs: jobs:
prepare_list:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "matrix=[$(ls -A1 moto | grep -v '.py' | awk '{ printf "%s\047%s\047", (NR==1?"":", "), $0 } END{ print "" }')]" >> $GITHUB_OUTPUT
- run: echo "matrix=[$(ls -A1 moto | grep -v '.py' | awk '{ printf "%s\047%s\047", (NR==1?"":", "), $0 } END{ print "" }')]"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
runtest: runtest:
name: Run Dependency Test name: Run Dependency Test
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: prepare_list
strategy: strategy:
matrix: matrix:
python-version: [ 3.8 ] python-version: [ 3.8 ]
service: ${{ fromJson(needs.prepare_list.outputs.matrix) }}
steps: steps:
- name: Checkout repo - name: Checkout repo
@ -25,11 +36,4 @@ jobs:
AWS_ACCESS_KEY_ID: key AWS_ACCESS_KEY_ID: key
AWS_SECRET_ACCESS_KEY: secret AWS_SECRET_ACCESS_KEY: secret
run: | run: |
scripts/dependency_test.sh scripts/dependency_test.sh ${{ matrix.service }}
- name: Archive logs
if: always()
uses: actions/upload-artifact@v3
with:
name: buildfolder-${{ matrix.python-version }}
path: |
test_results_*.log

View File

@ -33,7 +33,7 @@ valid_service() {
# Verify whether this is a valid service # Verify whether this is a valid service
# We'll ignore metadata folders, and folders that test generic Moto behaviour # We'll ignore metadata folders, and folders that test generic Moto behaviour
# We'll also ignore CloudFormation, as it will always depend on other services # We'll also ignore CloudFormation, as it will always depend on other services
local ignore_moto_folders="core instance_metadata __pycache__ templates cloudformation moto_api resourcegroupstaggingapi packages utilities s3bucket_path" local ignore_moto_folders="core instance_metadata __pycache__ templates cloudformation moto_api moto_server resourcegroupstaggingapi packages utilities s3bucket_path"
if echo $ignore_moto_folders | grep -q "$1"; then if echo $ignore_moto_folders | grep -q "$1"; then
return 1 return 1
else else
@ -46,53 +46,43 @@ test_service() {
path_to_test_file=$2 path_to_test_file=$2
venv_path="test_venv_${service}" venv_path="test_venv_${service}"
overwrite "Running tests for ${service}.." overwrite "Running tests for ${service}.."
python -m venv ${venv_path} > /dev/null python -m venv ${venv_path}
source ${venv_path}/bin/activate > /dev/null source ${venv_path}/bin/activate
pip install --upgrade pip setuptools
# Can't just install requirements-file, as it points to all dependencies # Can't just install requirements-file, as it points to all dependencies
pip install -r requirements-tests.txt > /dev/null pip install -r requirements-tests.txt
pip install .[$service] > /dev/null 2>&1 pip install .[$service]
pip install boto > /dev/null 2>&1 pip install boto
if [[ $service != "xray" ]]; then if [[ $service != "xray" ]]; then
pip uninstall setuptools pkg_resources -y > /dev/null 2>&1 pip uninstall setuptools pkg_resources -y
fi fi
# Restart venv - ensure these deps are loaded # Restart venv - ensure these deps are loaded
deactivate deactivate
source ${venv_path}/bin/activate > /dev/null source ${venv_path}/bin/activate
# Run tests for this service # Run tests for this service
test_result_filename="test_results_${service}.log" pytest -sv --ignore-glob="**/test_server.py" --ignore-glob="**/test_*_cloudformation.py" --ignore-glob="**/test_*_integration.py" $path_to_test_file
touch $test_result_filename
pytest -sv --ignore-glob="**/test_server.py" --ignore-glob="**/test_*_cloudformation.py" --ignore-glob="**/test_*_integration.py" $path_to_test_file >$test_result_filename 2>&1
RESULT=$? RESULT=$?
if [[ $RESULT != 0 ]]; then
echo -e "Tests for ${service} have failed!\n"
else
rm $test_result_filename
fi
deactivate deactivate
rm -rf ${venv_path} rm -rf ${venv_path}
if [[ $RESULT != 0 ]]; then
echo -e "Tests for ${service} have failed!\n"
exit -1
fi
} }
echo "Running Dependency tests..." service=$1
ITER=0 if [[ $# -eq 0 ]] ; then
for file in moto/* echo 'Please add the name of the service you want to test as the first argument:'
do echo ' scripts/dependency_test.sh acm'
if [[ -d $file ]]; then exit 0
service=${file:5} fi
path_to_test_file="tests/test_${service}" echo "Running Dependency tests for {$1}..."
if valid_service $service && [[ -d $path_to_test_file ]]; then path_to_test_file="tests/test_${service}"
test_service $service $path_to_test_file & if valid_service $service && [[ -d $path_to_test_file ]]; then
elif valid_service $service; then test_service $service $path_to_test_file
if [[ $? != 0 ]]; then
exit -1
fi
elif valid_service $service; then
echo -e "No tests for ${service} can be found on ${path_to_test_file}!\n" echo -e "No tests for ${service} can be found on ${path_to_test_file}!\n"
fi fi
if (( $ITER % 4 == 0 )); then
# Ensure we're only processing 4 services at the time
wait
fi
fi
ITER=$(expr $ITER + 1)
done
wait
nr_of_failed_services=$(ls -1q test_results*.log 2>/dev/null | wc -l)
echo "Nr of failed services: ${nr_of_failed_services}"
exit $((nr_of_failed_services))