Skip to content

Commit

Permalink
Migrate to clients test image (#3415)
Browse files Browse the repository at this point in the history
* Migrate to client-testing image

- Use clients-testing image for standalone and cluster
- Remove hardcoded TLS certificates and keys
- Remove stunnel
- Remove Cluster docker and configs

* Fix migration bugs

* Create reusable action to run tests

- Reduce copy paste by using reusable action for running tests
- Gain better control of tests matrix

Add missing actions checkout

More fixes in integration workflow

Another attempt to fix matrix

* Reorg test matrix

* Fix jobs names and execution order

* Execute standalone and cluster test simultaneously

* Streamline test execution

- Automatically map Redis version to Redis Stack version and use it for testing module commands
- Remove Graph commands from execution by default
- Include more Redis versions to the test matrix

* More fixes to integration job

* Move python compatibility tests to a separate task

* Improve run-tests action

* Add missing pytest marks for TS tests

* Fix cluster configuration

* Debug cluster tests

* Fix Cluster TLS port

* Move current redis version to env var

* Fix ssl tests

* Show CLUSTER NODES on fail

* Fix integration workflow bugs

* Add workarounds for IPv6 bug in tests

* Use hostname instead of hardcoded IPv4 loopback

* Fix bug in _get_client

* Fix run-tests action

* Fix imports

* Add missing version guards in search tests

* Add compatibility for Redis < 7

* Add missing version guard in search tests

* Fix run-tests

* Add missing tls-auth-clients option

* Skip module tests when Redis < 7 and RESP3 is enabled

* Fix async test_moved_redirection_on_slave_with_default

The test was broken for a while after migrating to all-in-one container with Cluster

* Cleanup test after debugging

* Use correct profile in install_and_test.sh

* Use matrix to execute hiredis<=3.0.0 tests

* Fix hiredis job

* Fix pytest command in install_and_test.sh

* Use 7.4.1 as default version in docker-compose.yml

* Fix uvloop-tests
  • Loading branch information
uglide authored Nov 21, 2024
1 parent 00f5be4 commit 3d45064
Show file tree
Hide file tree
Showing 37 changed files with 503 additions and 595 deletions.
147 changes: 147 additions & 0 deletions .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: 'Run redis-py tests'
description: 'Runs redis-py tests against different Redis versions and configurations'
inputs:
python-version:
description: 'Python version to use for running tests'
default: '3.12'
parser-backend:
description: 'Parser backend to use: plain or hiredis'
required: true
redis-version:
description: 'Redis version to test against'
required: true
hiredis-version:
description: 'hiredis version to test against'
required: false
default: '>3.0.0'
event-loop:
description: 'Event loop to use'
required: false
default: 'asyncio'
runs:
using: "composite"
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'

- name: Setup Test environment
env:
REDIS_VERSION: ${{ inputs.redis-version }}
REDIS_IMAGE: "redis:${{ inputs.redis-version }}"
CLIENT_LIBS_TEST_IMAGE: "redislabs/client-libs-test:${{ inputs.redis-version }}"
run: |
set -e
echo "::group::Installing dependencies"
pip install -U setuptools wheel
pip install -r requirements.txt
pip install -r dev_requirements.txt
if [ "${{inputs.parser-backend}}" == "hiredis" ]; then
pip install "hiredis${{inputs.hiredis-version}}"
echo "PARSER_BACKEND=$(echo "${{inputs.parser-backend}}_${{inputs.hiredis-version}}" | sed 's/[^a-zA-Z0-9]/_/g')" >> $GITHUB_ENV
else
echo "PARSER_BACKEND=${{inputs.parser-backend}}" >> $GITHUB_ENV
fi
echo "::endgroup::"
echo "::group::Starting Redis servers"
redis_major_version=$(echo "$REDIS_VERSION" | grep -oP '^\d+')
if (( redis_major_version < 8 )); then
echo "Using redis-stack for module tests"
# Mapping of redis version to stack version
declare -A redis_stack_version_mapping=(
["7.4.1"]="7.4.0-v1"
["7.2.6"]="7.2.0-v13"
["6.2.16"]="6.2.6-v17"
)
if [[ -v redis_stack_version_mapping[$REDIS_VERSION] ]]; then
export REDIS_STACK_IMAGE="redis/redis-stack-server:${redis_stack_version_mapping[$REDIS_VERSION]}"
echo "REDIS_MOD_URL=redis://127.0.0.1:6479/0" >> $GITHUB_ENV
else
echo "Version not found in the mapping."
exit 1
fi
if (( redis_major_version < 7 )); then
export REDIS_STACK_EXTRA_ARGS="--tls-auth-clients optional --save ''"
export REDIS_EXTRA_ARGS="--tls-auth-clients optional --save ''"
echo "REDIS_MAJOR_VERSION=${redis_major_version}" >> $GITHUB_ENV
fi
invoke devenv --endpoints=all-stack
else
echo "Using redis CE for module tests"
echo "REDIS_MOD_URL=redis://127.0.0.1:6379" >> $GITHUB_ENV
invoke devenv --endpoints all
fi
sleep 10 # time to settle
echo "::endgroup::"
shell: bash

- name: Run tests
run: |
set -e
run_tests() {
local protocol=$1
local eventloop=""
if [ "${{inputs.event-loop}}" == "uvloop" ]; then
eventloop="--uvloop"
fi

echo "::group::RESP${protocol} standalone tests"
echo "REDIS_MOD_URL=${REDIS_MOD_URL}"

if (( $REDIS_MAJOR_VERSION < 7 )) && [ "$protocol" == "3" ]; then
echo "Skipping module tests: Modules doesn't support RESP3 for Redis versions < 7"
invoke standalone-tests --redis-mod-url=${REDIS_MOD_URL} $eventloop --protocol="${protocol}" --extra-markers="not redismod"
else
invoke standalone-tests --redis-mod-url=${REDIS_MOD_URL} $eventloop --protocol="${protocol}"
fi

echo "::endgroup::"

if [ "$protocol" == "2" ] || [ "${{inputs.parser-backend}}" != 'hiredis' ]; then
echo "::group::RESP${protocol} cluster tests"
invoke cluster-tests $eventloop --protocol=${protocol}
echo "::endgroup::"
fi
}

run_tests 2 "${{inputs.event-loop}}"
run_tests 3 "${{inputs.event-loop}}"
shell: bash

- name: Debug
if: failure()
run: |
sudo apt-get install -y redis-tools
echo "Docker Containers:"
docker ps
redis-cli -p 16379 CLUSTER NODES
shell: bash

- name: Upload test results and profiling data
uses: actions/upload-artifact@v4
with:
name: pytest-results-redis_${{inputs.redis-version}}-python_${{inputs.python-version}}-parser_${{env.PARSER_BACKEND}}-el_${{inputs.event-loop}}
path: |
*-results.xml
prof/**
profile_output*
if-no-files-found: error
retention-days: 10

- name: Upload codecov coverage
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
8 changes: 5 additions & 3 deletions .github/workflows/install_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ python -m venv ${DESTENV}
source ${DESTENV}/bin/activate
pip install --upgrade --quiet pip
pip install --quiet -r dev_requirements.txt
invoke devenv
invoke devenv --endpoints=all-stack
invoke package

# find packages
Expand All @@ -39,7 +39,9 @@ cd ${TESTDIR}
# install, run tests
pip install ${PKG}
# Redis tests
pytest -m 'not onlycluster'
pytest -m 'not onlycluster and not graph'
# RedisCluster tests
CLUSTER_URL="redis://localhost:16379/0"
pytest -m 'not onlynoncluster and not redismod and not ssl' --redis-url=${CLUSTER_URL}
CLUSTER_SSL_URL="rediss://localhost:27379/0"
pytest -m 'not onlynoncluster and not redismod and not ssl and not graph' \
--redis-url="${CLUSTER_URL}" --redis-ssl-url="${CLUSTER_SSL_URL}"
Loading

0 comments on commit 3d45064

Please sign in to comment.