From 9b2e5f41f3f984e03af7e724d52d78c7f601728a Mon Sep 17 00:00:00 2001 From: Juan Lee Date: Thu, 3 Dec 2026 14:54:23 -0700 Subject: [PATCH] chore: run the integration tests on CodeBuild runners integration_tests_codebuild.yml and blue_green_integration_tests_codebuild.yml now run the jobs of integration_tests.yml and blue_green_integration_tests.yml on CodeBuild-hosted runners and take their push triggers. The originals keep workflow_dispatch as the GitHub-hosted fallback. The custom endpoint workflow moves to integration_tests_custom_endpoint.yml. CodeBuild jobs share outbound addresses. Each job opens TCP 3306 and 5432 on the default security group to its own address and records it, and one job per run revokes every recorded address. The workflows set SKIP_IP_AUTHORIZATION, so the harness never revokes a rule that another job still uses, and TEST_CONTAINER_REGISTRY=ecr, so the images come from ECR Public instead of Docker Hub. Both workflows share one concurrency group, so one run's revoke job can't cut off the other's jobs. Harness changes: - ContainerImages holds every image name. dockerhub, the default, keeps the current names, and a value other than dockerhub or ecr fails at once. With ecr, the Gradle test tasks turn off Ryuk and the Testcontainers startup check unless those variables are set. - Before each AWS environment build, sweeps delete test- clusters, instances, parameter groups, Blue/Green deployments and "Test run at" rules that are more than 12 hours old. Unless SWEEP_DRY_RUN is false, they only log. The workflows set it to false only on main. - An environment that fails to build now deletes what it created. Each delete skips an empty identifier and acts only on the cluster it asked for, because a lookup with no identifier returns every cluster in the region. - The harness rule is TCP 3306 and 5432 instead of every port, the RDS and EC2 clients retry throttling with the adaptive strategy, and the log names the Docker host that Testcontainers uses. The workflows set MYSQL_VERSION, PG_VERSION and RDS_DB_REGION instead of four names the harness no longer reads, so the Latest stage now tests the latest engine versions. Each test job sets a random, masked DB_PASSWORD. Aurora MySQL 8.4 refuses unencrypted connections, so the aiomysql test connections now use TLS without verifying the server certificate, as mysql-connector does by default. --- .../codebuild-authorize-runner-ip/action.yml | 73 +++ .../codebuild-revoke-runner-ips/action.yml | 50 ++ .github/workflows/autoscaling_tests.yml | 10 +- .../blue_green_integration_tests.yml | 19 +- ...blue_green_integration_tests_codebuild.yml | 130 +++++ .github/workflows/integration_tests.yml | 36 +- .../workflows/integration_tests_codebuild.yml | 173 ++++++- .../integration_tests_custom_endpoint.yml | 71 +++ .github/workflows/mysql_performance_tests.yml | 14 +- .github/workflows/pg_performance_tests.yml | 14 +- docs/development-guide/IntegrationTests.md | 58 ++- .../utils/async_connection_helpers.py | 2 + .../container/utils/connection_utils.py | 3 + .../container/utils/driver_helper.py | 12 +- tests/integration/host/build.gradle.kts | 9 + .../integration/host/TestEnvironment.java | 239 +++++---- .../host/TestEnvironmentConfiguration.java | 2 + .../integration/util/AuroraTestUtility.java | 483 ++++++++++++++++-- .../integration/util/ContainerHelper.java | 20 +- .../integration/util/ContainerImages.java | 108 ++++ .../test/resources/simplelogger.properties | 2 + 21 files changed, 1303 insertions(+), 225 deletions(-) create mode 100644 .github/actions/codebuild-authorize-runner-ip/action.yml create mode 100644 .github/actions/codebuild-revoke-runner-ips/action.yml create mode 100644 .github/workflows/blue_green_integration_tests_codebuild.yml create mode 100644 .github/workflows/integration_tests_custom_endpoint.yml create mode 100644 tests/integration/host/src/test/java/integration/util/ContainerImages.java diff --git a/.github/actions/codebuild-authorize-runner-ip/action.yml b/.github/actions/codebuild-authorize-runner-ip/action.yml new file mode 100644 index 000000000..fe9109673 --- /dev/null +++ b/.github/actions/codebuild-authorize-runner-ip/action.yml @@ -0,0 +1,73 @@ +# Needs actions/checkout earlier in the job and AWS credentials in the environment. The caller +# uploads the ip-file output as artifact runner-ip- for codebuild-revoke-runner-ips. +name: 'Authorize the CodeBuild runner egress IP address' +description: 'Discovers this job''s egress IPv4 address, opens TCP 3306 and 5432 from it in the default security group, and writes it to a file.' +inputs: + id: + description: 'Identifier unique to this job within the run. Names the file runner-ip-.txt; use it in the artifact name runner-ip- as well.' + required: true +outputs: + ipv4: + description: 'The egress IPv4 address that was authorized.' + value: ${{ steps.ip.outputs.ipv4 }} + ip-file: + description: 'Path of the file holding the address, to upload as artifact runner-ip-.' + value: ${{ steps.ip.outputs.ip-file }} +runs: + using: 'composite' + steps: + - name: 'Discover this job''s egress IP address' + id: ip + shell: bash + env: + RUNNER_IP_FILE: ${{ runner.temp }}/runner-ip-${{ inputs.id }}.txt + run: | + if ! response=$(curl -fsS --max-time 10 https://checkip.amazonaws.com); then + echo "::error::checkip.amazonaws.com did not answer, so this job's egress IP address is unknown and the test databases would be unreachable." + exit 1 + fi + ipv4=$(printf '%s' "$response" | tr -d '[:space:]') + octet='(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' + ipv4_re="^($octet\.){3}$octet\$" + if ! [[ $ipv4 =~ $ipv4_re ]]; then + echo "::error::checkip.amazonaws.com did not return a dotted IPv4 address, so this job's egress IP address is unknown." + exit 1 + fi + echo "Runner egress IP address: $ipv4" + echo "ipv4=$ipv4" >> "$GITHUB_OUTPUT" + echo "$ipv4" > "$RUNNER_IP_FILE" + echo "ip-file=$RUNNER_IP_FILE" >> "$GITHUB_OUTPUT" + + # Only TCP 3306 and 5432 are opened, the ports the harness reaches (TestEnvironment.getPort()). + # Keep the description EXACTLY "Test run at " plus an ISO-8601 instant: + # AuroraTestUtility.securityGroupRulesCleanUp() calls Instant.parse on it + # and revokes the rule after 12 hours if revoke-runner-ip never ran. + # Appending anything opts the rule out. + # On InvalidPermission.Duplicate (shared address) the description is refreshed so the sweep keeps the rule. + # If 3306 succeeds and 5432 fails, nothing is recorded; the sweep reclaims it. + - name: 'Authorize this job''s egress IP address' + shell: bash + env: + RUNNER_IPV4: ${{ steps.ip.outputs.ipv4 }} + run: | + ipv4=$RUNNER_IPV4 + description="Test run at $(date -u +%Y-%m-%dT%H:%M:%SZ)" + for port in 3306 5432; do + permissions=$(printf \ + '[{"IpProtocol":"tcp","FromPort":%s,"ToPort":%s,"IpRanges":[{"CidrIp":"%s/32","Description":"%s"}]}]' \ + "$port" "$port" "$ipv4" "$description") + if output=$(aws ec2 authorize-security-group-ingress \ + --group-name default --ip-permissions "$permissions" 2>&1); then + echo "Authorized TCP $port from $ipv4/32." + elif [ "${output#*InvalidPermission.Duplicate}" != "$output" ]; then + if ! output=$(aws ec2 update-security-group-rule-descriptions-ingress \ + --group-name default --ip-permissions "$permissions" 2>&1); then + echo "$output" + exit 1 + fi + echo "TCP $port from $ipv4/32 was already authorized; refreshed its description." + else + echo "$output" + exit 1 + fi + done diff --git a/.github/actions/codebuild-revoke-runner-ips/action.yml b/.github/actions/codebuild-revoke-runner-ips/action.yml new file mode 100644 index 000000000..4397bc712 --- /dev/null +++ b/.github/actions/codebuild-revoke-runner-ips/action.yml @@ -0,0 +1,50 @@ +# Needs actions/checkout, AWS credentials, and the runner-ip-* artifacts downloaded (merge-multiple) into ip-dir. +name: 'Revoke the CodeBuild runner egress IP addresses' +description: 'Revokes TCP 3306 and 5432 for every address recorded in ip-dir. Missing rules and an empty directory are not errors.' +inputs: + ip-dir: + description: 'Directory holding the downloaded runner-ip-*.txt files.' + required: true +runs: + using: 'composite' + steps: + - name: 'Revoke the recorded egress IP addresses' + shell: bash + env: + RUNNER_IP_DIR: ${{ inputs.ip-dir }} + run: | + shopt -s nullglob + files=("$RUNNER_IP_DIR"/runner-ip-*.txt) + if [ ${#files[@]} -eq 0 ]; then + echo "No matrix job recorded an authorized address; nothing to revoke." + exit 0 + fi + octet='(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' + ipv4_re="^($octet\.){3}$octet\$" + while IFS= read -r ipv4; do + if ! [[ $ipv4 =~ $ipv4_re ]]; then + echo "::warning::Skipping a recorded egress address that is not a dotted IPv4 address." + continue + fi + for port in 3306 5432; do + permissions=$(printf \ + '[{"IpProtocol":"tcp","FromPort":%s,"ToPort":%s,"IpRanges":[{"CidrIp":"%s/32"}]}]' \ + "$port" "$port" "$ipv4") + if output=$(aws ec2 revoke-security-group-ingress \ + --group-name default --ip-permissions "$permissions" 2>&1); then + # In a default VPC an unmatched revoke is not an error: the rules that were not found + # come back under UnknownIpPermissions, so echo the response instead of claiming the + # rule was there. A non-default VPC raises InvalidPermission.NotFound, handled below. + echo "Revoke of TCP $port from $ipv4/32 accepted:" + echo "$output" + elif [ "${output#*InvalidPermission.NotFound}" != "$output" ]; then + # Already gone, e.g. revoked by hand or by the 12-hour sweep. + echo "TCP $port from $ipv4/32 was already revoked." + else + # Revoke the rest before failing. + echo "$output" + status=1 + fi + done + done < <(cat "${files[@]}" | tr -d '\r' | awk 'NF' | sort -u) + exit "${status:-0}" diff --git a/.github/workflows/autoscaling_tests.yml b/.github/workflows/autoscaling_tests.yml index 91c5c5c07..751b21beb 100644 --- a/.github/workflows/autoscaling_tests.yml +++ b/.github/workflows/autoscaling_tests.yml @@ -39,12 +39,18 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run Autoscaling Tests' run: | ./gradlew --no-parallel --no-daemon test-autoscaling --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} - AURORA_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive results' if: always() diff --git a/.github/workflows/blue_green_integration_tests.yml b/.github/workflows/blue_green_integration_tests.yml index b8b0bc8d0..b0b8c45c7 100644 --- a/.github/workflows/blue_green_integration_tests.yml +++ b/.github/workflows/blue_green_integration_tests.yml @@ -1,18 +1,8 @@ name: Blue/Green Integration Tests on: + # The push trigger is in blue_green_integration_tests_codebuild.yml, which runs these tests on CodeBuild runners. workflow_dispatch: - push: - branches: - - main - paths-ignore: - - '**/*.md' - - '**/*.jpg' - - '**/README.txt' - - '**/LICENSE.txt' - - 'docs/**' - - 'ISSUE_TEMPLATE/**' - - '**/remove-old-artifacts.yml' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -60,6 +50,12 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run Blue/Green Integration Tests' run: | ./gradlew --no-parallel --no-daemon test-bgd-${{ matrix.task }} --info @@ -67,6 +63,7 @@ jobs: RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} MYSQL_VERSION: default PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive Blue/Green results' if: always() diff --git a/.github/workflows/blue_green_integration_tests_codebuild.yml b/.github/workflows/blue_green_integration_tests_codebuild.yml new file mode 100644 index 000000000..cd3316ca1 --- /dev/null +++ b/.github/workflows/blue_green_integration_tests_codebuild.yml @@ -0,0 +1,130 @@ +name: Blue/Green Integration Tests (CodeBuild) + +on: + workflow_dispatch: + push: + branches: + - main + paths-ignore: + - '**/*.md' + - '**/*.jpg' + - '**/README.txt' + - '**/LICENSE.txt' + - 'docs/**' + - 'ISSUE_TEMPLATE/**' + - '**/remove-old-artifacts.yml' + +concurrency: + # Shared with the other CodeBuild workflow: jobs share outbound IPs, and each run's last job revokes their database rules. + group: rds-integration-tests-codebuild + cancel-in-progress: false + +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout + +env: + # CodeBuild runners share outbound addresses, and Docker Hub limits anonymous pulls per address. + TEST_CONTAINER_REGISTRY: ecr + # Each job authorizes its address and one job revokes them all, so the harness must not revoke + # a rule that other jobs on the same address still use. + SKIP_IP_AUTHORIZATION: true + +jobs: + blue-green-integration-tests: + name: Run Blue/Green Integration Tests + runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }} + timeout-minutes: 120 + strategy: + fail-fast: false + max-parallel: 2 + matrix: + task: [ "mysql-aurora-sync", "mysql-aurora-async", "pg-aurora-sync", "pg-aurora-async" ] + + steps: + - name: 'Clone repository' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: 'Set up JDK 8' + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 + with: + distribution: 'corretto' + java-version: 8 + + - name: 'Configure AWS Credentials' + uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} + role-session-name: python_bg_integration_tests + role-duration-seconds: 21600 + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: 'Authorize the runner IP address' + id: ip + uses: ./.github/actions/codebuild-authorize-runner-ip + with: + id: bgd-${{ matrix.task }} + + - name: 'Record the runner IP address' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runner-ip-bgd-${{ matrix.task }} + path: ${{ steps.ip.outputs.ip-file }} + if-no-files-found: error + retention-days: 1 + + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + + - name: 'Run Blue/Green Integration Tests' + run: | + ./gradlew --no-parallel --no-daemon test-bgd-${{ matrix.task }} --info + env: + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + MYSQL_VERSION: default + PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} + + - name: 'Archive Blue/Green results' + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: pytest-integration-report-bgd-${{ matrix.task }} + path: ./tests/integration/container/reports + retention-days: 5 + + revoke-runner-ip: + name: 'Revoke runner IP' + runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }} + timeout-minutes: 30 + needs: blue-green-integration-tests + if: always() + + steps: + - name: 'Clone repository' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + fetch-depth: 1 + + - name: 'Configure AWS Credentials' + uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} + role-session-name: python_bg_integration_tests + role-duration-seconds: 21600 + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: 'Download the recorded runner IP addresses' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: runner-ip-* + merge-multiple: true + path: ${{ runner.temp }}/runner-ips + + - name: 'Revoke the recorded runner IP addresses' + uses: ./.github/actions/codebuild-revoke-runner-ips + with: + ip-dir: ${{ runner.temp }}/runner-ips diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 76519f84d..0c57b5c04 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -1,18 +1,8 @@ name: Integration Tests on: + # The push trigger is in integration_tests_codebuild.yml, which runs these tests on CodeBuild runners. workflow_dispatch: - push: - branches: - - main - paths-ignore: - - '**/*.md' - - '**/*.jpg' - - '**/README.txt' - - '**/LICENSE.txt' - - 'docs/**' - - 'ISSUE_TEMPLATE/**' - - '**/remove-old-artifacts.yml' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -59,14 +49,20 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run LTS Integration Tests' run: | ./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - AURORA_MYSQL_DB_ENGINE_VERSION: lts - AURORA_PG_ENGINE_VERSION: lts + MYSQL_VERSION: default + PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive LTS results' if: always() @@ -113,14 +109,20 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run Latest Integration Tests' run: | ./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - AURORA_MYSQL_DB_ENGINE_VERSION: latest - AURORA_PG_ENGINE_VERSION: latest + MYSQL_VERSION: latest + PG_VERSION: latest + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive Latest results' if: always() diff --git a/.github/workflows/integration_tests_codebuild.yml b/.github/workflows/integration_tests_codebuild.yml index b8f63c3d7..003b5862b 100644 --- a/.github/workflows/integration_tests_codebuild.yml +++ b/.github/workflows/integration_tests_codebuild.yml @@ -1,24 +1,46 @@ -name: Integration Tests CodeBuild +name: Integration Tests (CodeBuild) on: workflow_dispatch: + push: + branches: + - main + paths-ignore: + - '**/*.md' + - '**/*.jpg' + - '**/README.txt' + - '**/LICENSE.txt' + - 'docs/**' + - 'ISSUE_TEMPLATE/**' + - '**/remove-old-artifacts.yml' + +concurrency: + # Shared with the other CodeBuild workflow: jobs share outbound IPs, and each run's last job revokes their database rules. + group: rds-integration-tests-codebuild + cancel-in-progress: false permissions: id-token: write # This is required for requesting the JWT contents: read # This is required for actions/checkout +env: + # CodeBuild runners share outbound addresses, and Docker Hub limits anonymous pulls per address. + TEST_CONTAINER_REGISTRY: ecr + # Each job authorizes its address and one job revokes them all, so the harness must not revoke + # a rule that other jobs on the same address still use. + SKIP_IP_AUTHORIZATION: true + jobs: - build-integration-tests-codebuild: - name: Run Integration Tests With CodeBuild + lts-integration-tests: + name: Run LTS Integration Tests + runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }} + timeout-minutes: 330 strategy: fail-fast: false matrix: - python-version: [ "3.11", "3.12", "3.13", "3.14" ] + python-version: [ "3.11", "3.12", "3.13", "3.14" ] environment: [ "mysql", "pg" ] - runs-on: ubuntu-latest - environment: ${{ matrix.environment }}_integ - steps: - name: 'Clone repository' uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 @@ -29,37 +51,146 @@ jobs: distribution: 'corretto' java-version: 8 - - name: Install poetry - shell: bash + - name: 'Configure AWS Credentials' + uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} + role-session-name: python_integration_tests + role-duration-seconds: 21600 + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: 'Authorize the runner IP address' + id: ip + uses: ./.github/actions/codebuild-authorize-runner-ip + with: + id: lts-${{ matrix.python-version }}-${{ matrix.environment }} + + - name: 'Record the runner IP address' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runner-ip-lts-${{ matrix.python-version }}-${{ matrix.environment }} + path: ${{ steps.ip.outputs.ip-file }} + if-no-files-found: error + retention-days: 1 + + - name: 'Set a random database password' run: | - pipx install poetry==1.8.2 - poetry config virtualenvs.prefer-active-python true + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + + - name: 'Run LTS Integration Tests' + run: | + ./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info + env: + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + MYSQL_VERSION: default + PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} + + - name: 'Archive LTS results' + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: pytest-integration-report-${{ matrix.python-version }}-${{ matrix.environment }}-lts + path: ./tests/integration/container/reports + retention-days: 5 + + latest-integration-tests: + name: Run Latest Integration Tests + runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }} + timeout-minutes: 330 + needs: lts-integration-tests + strategy: + fail-fast: false + matrix: + python-version: [ "3.11", "3.12", "3.13", "3.14" ] + environment: [ "mysql", "pg" ] - - name: Install dependencies - run: poetry install + steps: + - name: 'Clone repository' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: 'Set up JDK 8' + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 + with: + distribution: 'corretto' + java-version: 8 - name: 'Configure AWS Credentials' uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 with: role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} - role-session-name: python_integration_codebuild_tests + role-session-name: python_integration_tests role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} - - name: 'Run Integration Tests' + - name: 'Authorize the runner IP address' + id: ip + uses: ./.github/actions/codebuild-authorize-runner-ip + with: + id: latest-${{ matrix.python-version }}-${{ matrix.environment }} + + - name: 'Record the runner IP address' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runner-ip-latest-${{ matrix.python-version }}-${{ matrix.environment }} + path: ${{ steps.ip.outputs.ip-file }} + if-no-files-found: error + retention-days: 1 + + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + + - name: 'Run Latest Integration Tests' run: | ./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - RDS_ENDPOINT: ${{ secrets.RDS_ENDPOINT }} - AURORA_MYSQL_DB_ENGINE_VERSION: "latest" - AURORA_PG_ENGINE_VERSION: "latest" + MYSQL_VERSION: latest + PG_VERSION: latest + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - - name: 'Archive results' + - name: 'Archive Latest results' if: always() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: - name: pytest-integration-report-${{ matrix.python-version }}-${{ matrix.environment }} + name: pytest-integration-report-${{ matrix.python-version }}-${{ matrix.environment }}-latest path: ./tests/integration/container/reports retention-days: 5 + + revoke-runner-ip: + name: 'Revoke runner IP' + runs-on: codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }} + timeout-minutes: 30 + needs: [ lts-integration-tests, latest-integration-tests ] + if: always() + + steps: + - name: 'Clone repository' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + fetch-depth: 1 + + - name: 'Configure AWS Credentials' + uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} + role-session-name: python_integration_tests + role-duration-seconds: 21600 + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: 'Download the recorded runner IP addresses' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: runner-ip-* + merge-multiple: true + path: ${{ runner.temp }}/runner-ips + + - name: 'Revoke the recorded runner IP addresses' + uses: ./.github/actions/codebuild-revoke-runner-ips + with: + ip-dir: ${{ runner.temp }}/runner-ips diff --git a/.github/workflows/integration_tests_custom_endpoint.yml b/.github/workflows/integration_tests_custom_endpoint.yml new file mode 100644 index 000000000..849a06d80 --- /dev/null +++ b/.github/workflows/integration_tests_custom_endpoint.yml @@ -0,0 +1,71 @@ +name: Integration Tests Custom Endpoint + +on: + workflow_dispatch: + +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout + +jobs: + custom-endpoint-integration-tests: + name: Run Custom Endpoint Integration Tests + strategy: + fail-fast: false + matrix: + python-version: [ "3.11", "3.12", "3.13", "3.14" ] + environment: [ "mysql", "pg" ] + + runs-on: ubuntu-latest + environment: ${{ matrix.environment }}_integ + + steps: + - name: 'Clone repository' + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + + - name: 'Set up JDK 8' + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 + with: + distribution: 'corretto' + java-version: 8 + + - name: Install poetry + shell: bash + run: | + pipx install poetry==1.8.2 + poetry config virtualenvs.prefer-active-python true + + - name: Install dependencies + run: poetry install + + - name: 'Configure AWS Credentials' + uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }} + role-session-name: python_integration_codebuild_tests + role-duration-seconds: 21600 + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + + - name: 'Run Integration Tests' + run: | + ./gradlew --no-parallel --no-daemon test-python-${{ matrix.python-version }}-${{ matrix.environment }} --info + env: + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + RDS_ENDPOINT: ${{ secrets.RDS_ENDPOINT }} + MYSQL_VERSION: latest + PG_VERSION: latest + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} + + - name: 'Archive results' + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: pytest-integration-report-${{ matrix.python-version }}-${{ matrix.environment }} + path: ./tests/integration/container/reports + retention-days: 5 diff --git a/.github/workflows/mysql_performance_tests.yml b/.github/workflows/mysql_performance_tests.yml index 43f841bfd..3fdd41d64 100644 --- a/.github/workflows/mysql_performance_tests.yml +++ b/.github/workflows/mysql_performance_tests.yml @@ -41,14 +41,20 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run MySQL Performance Tests' run: | ./gradlew --no-parallel --no-daemon test-mysql-aurora-performance --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} - AURORA_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - AURORA_MYSQL_DB_ENGINE_VERSION: "lts" - AURORA_PG_ENGINE_VERSION: "lts" + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + MYSQL_VERSION: default + PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive results' if: always() diff --git a/.github/workflows/pg_performance_tests.yml b/.github/workflows/pg_performance_tests.yml index cc10ec560..bbcea12de 100644 --- a/.github/workflows/pg_performance_tests.yml +++ b/.github/workflows/pg_performance_tests.yml @@ -39,14 +39,20 @@ jobs: role-duration-seconds: 21600 aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + - name: 'Set a random database password' + run: | + password=$(openssl rand -hex 16) + echo "::add-mask::$password" + echo "DB_PASSWORD=$password" >> "$GITHUB_ENV" + - name: 'Run PG Performance Tests' run: | ./gradlew --no-parallel --no-daemon test-pg-aurora-performance --info env: - RDS_CLUSTER_DOMAIN: ${{ secrets.DB_CONN_SUFFIX }} - AURORA_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - AURORA_MYSQL_DB_ENGINE_VERSION: "lts" - AURORA_PG_ENGINE_VERSION: "lts" + RDS_DB_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + MYSQL_VERSION: default + PG_VERSION: default + SWEEP_DRY_RUN: ${{ github.ref_name != 'main' }} - name: 'Archive results' if: always() diff --git a/docs/development-guide/IntegrationTests.md b/docs/development-guide/IntegrationTests.md index 3e018297b..720ed8e27 100644 --- a/docs/development-guide/IntegrationTests.md +++ b/docs/development-guide/IntegrationTests.md @@ -81,7 +81,9 @@ Async tests do not introduce any new pytest dependencies — they follow the rep **Aurora Serverless v2 operational notes:** -1. **Security-group allowlist is not managed automatically when `REUSE_RDS_DB=true`.** The harness skips IP authorization in reuse mode. Ensure the test runner's outbound IP is already in the target cluster's security group(s) before invoking any Gradle task; the first failure mode otherwise is connection refused / network unreachable. +1. **The harness manages only the region's `default` security group, also when `REUSE_RDS_DB=true`.** + In reuse mode it still adds a rule for the runner's IP address there (TCP 3306 and 5432), and it leaves the rule in place when the run ends. + If the reused cluster uses another security group, add the runner's outbound IP address to that group before you run any Gradle task, or connections to the cluster fail. 2. **Cold-start latency.** Serverless v2 can take 30–60 seconds to scale from 0 ACUs on the first connection. Warm the cluster with a trivial query (`SELECT 1`) before running timing-sensitive tests so that warmup cost isn't charged against a test's 600-second timeout. 3. **Topology-gated tests skip environmentally.** Multi-instance tests (failover, some read/write splitting assertions) need ≥2 instances to execute; they skip on single-writer topologies. Blue/Green and Global Database tests require specific engine versions / cluster configurations. Tests skipped under these conditions are environmental, not regressions — they are equivalent to the sync suite's existing behavior under the same cluster topology. @@ -138,17 +140,25 @@ Async tests do not introduce any new pytest dependencies — they follow the rep | Environment Variable Name | Required | Description | Example Value | |---------------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------| -| `DB_USERNAME` | Yes | The username to access the database. | `admin` | -| `DB_PASSWORD` | Yes | The database cluster password. | `password` | -| `DB_DATABASE_NAME` | No | Name of the database that will be used by the tests. The default database name is test. | `test_db_name` | -| `RDS_DB_NAME` | Yes | The database identifier for your Aurora or RDS cluster. Must be a unique value to avoid conflicting with existing clusters. | `db-identifier` | +| `DB_USERNAME` | No | The username to access the database. Defaults to `test_user`. | `admin` | +| `DB_PASSWORD` | No | The database password. Defaults to `secret_password`. | `password` | +| `DB_DATABASE_NAME` | No | Name of the database that will be used by the tests. The default database name is `test_database`. | `test_db_name` | +| `RDS_DB_NAME` | No | The identifier of the existing Aurora cluster, Multi-AZ DB cluster or Multi-AZ DB instance to use, required when `REUSE_RDS_DB` is true. Without reuse, the harness gives the database it creates this identifier, or a random one that starts with `test-` when this is unset. | `db-identifier` | | `RDS_DB_DOMAIN` | No | The existing database connection suffix. Use this variable to run against an existing database. | `XYZ.us-east-2.rds.amazonaws.com` | | `IAM_USER` | No | User within the database that is identified with AWSAuthenticationPlugin. This is used for AWS IAM Authentication and is optional | `example_user_name` | | `AWS_ACCESS_KEY_ID` | Yes | An AWS access key associated with an IAM user or role with RDS permissions. | `ASIAIOSFODNN7EXAMPLE` | | `AWS_SECRET_ACCESS_KEY` | Yes | The secret key associated with the provided AWS_ACCESS_KEY_ID. | `wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY` | -| `AWS_SESSION_TOKEN` | No | AWS Session Token for CLI, SDK, & API access. This value is for MFA credentials only. See: [temporary AWS credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html). | `AQoDYXdzEJr...` | | -| `REUSE_RDS_DB` | Yes | Set to true if you would like to use an existing cluster for your tests. | `false` | -| `RDS_DB_REGION` | Yes | The database region. | `us-east-2` | +| `AWS_SESSION_TOKEN` | No | The session token that comes with temporary AWS credentials, for example from an assumed role or MFA. See: [temporary AWS credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html). | `AQoDYXdzEJr...` | +| `REUSE_RDS_DB` | No | Set to true to run the tests against an existing database instead of creating one. Defaults to false. | `false` | +| `RDS_DB_REGION` | No | The database region. Defaults to `us-east-2`. | `us-east-2` | +| `MYSQL_VERSION` | No | The MySQL engine version of the Aurora and RDS test databases: `default` for the RDS default version, `latest` for the newest version, or a version number. Unset means `default`. | `latest` | +| `PG_VERSION` | No | The PostgreSQL engine version of the Aurora and RDS test databases, with the same values as `MYSQL_VERSION`. Unset means `default`. | `default` | +| `NUM_INSTANCES` | No | Runs only the test environments with this number of database instances: `1`, `2`, `3` or `5`. When unset, the tests run on every supported size except 3-instance Aurora clusters. | `2` | +| `FILTER` | No | A pytest `-k` expression that selects the tests to run. See [Filtering tests](#filtering-tests). | `test_iam` | +| `RDS_ENDPOINT` | No | A custom RDS API endpoint for the harness and the tests to use instead of the region's public one. | `https://rds.us-east-2.amazonaws.com` | +| `TEST_CONTAINER_REGISTRY` | No | Where the harness pulls its container images from: `dockerhub` (the default) or `ecr`, which takes the same images from Amazon ECR Public and so avoids the Docker Hub pull limit. Toxiproxy always comes from the GitHub container registry. With `ecr`, the Gradle test tasks also turn off the Testcontainers Ryuk container and startup check (`TESTCONTAINERS_RYUK_DISABLED` and `TESTCONTAINERS_CHECKS_DISABLE`) unless you set those yourself, because both pull from Docker Hub. Any other value fails the run before it creates anything. | `ecr` | +| `SKIP_IP_AUTHORIZATION` | No | Set to true when something else allows the runner's IP address in the region's `default` security group, as the CodeBuild workflows do. The harness then neither adds nor removes a rule for that address. Defaults to false. | `true` | +| `SWEEP_DRY_RUN` | No | Controls the cleanup sweeps that run before each AWS test environment is built (see [Continuous integration](#continuous-integration)). Only `false`, in any letter case, deletes stale `test-` resources. Any other value, or none, only logs what the sweeps would delete. The sweeps also run when `REUSE_RDS_DB` is true, so with `false` they can delete a reused database or its instances when the identifiers start with `test-` and the resources are more than 12 hours old. | `false` | | `DEBUG_ENV` | No | The IDE you will be using to debug the tests, values are either `PYCHARM` or `VSCODE` | `PYCHARM` | ## Managing Environment Variables @@ -239,3 +249,35 @@ can also be useful. The test results can be viewed in the test report generated at `tests/integration/container/reports/integration_tests.html`. The logs can be viewed from the console where you executed the tests or by clicking `show details` on a given test in the test report. + +## Continuous integration + +The CodeBuild workflows, `integration_tests_codebuild.yml` and `blue_green_integration_tests_codebuild.yml`, run the integration tests on CodeBuild-hosted GitHub Actions runners. +Their jobs use the runner label `codebuild-pythonWrapper-${{ github.run_id }}-${{ github.run_attempt }}` and pull the test images from Amazon ECR Public (`TEST_CONTAINER_REGISTRY=ecr`). + +CodeBuild runners can share a public IP address, so the workflow manages the security group rules instead of the harness: + +- Each test job adds TCP 3306 and 5432 rules for its runner's address to the region's `default` security group, and records the address as a `runner-ip-*` artifact. +- One revoke job runs after all test jobs, even when they fail, and removes the rules for every recorded address. +- The workflows set `SKIP_IP_AUTHORIZATION=true`, so the harness neither adds nor removes rules itself. + +The rule description is `Test run at