|
| 1 | +name: Run PostgreSQL Integration Tests |
| 2 | +description: "Run integration tests against PostgreSQL database" |
| 3 | + |
| 4 | +inputs: |
| 5 | + python-version: |
| 6 | + description: "Python version" |
| 7 | + required: true |
| 8 | + os: |
| 9 | + description: "Operating system" |
| 10 | + required: true |
| 11 | + |
| 12 | +runs: |
| 13 | + using: "composite" |
| 14 | + steps: |
| 15 | + - name: Set up Python ${{ inputs.python-version }} |
| 16 | + uses: actions/setup-python@v5 |
| 17 | + with: |
| 18 | + python-version: ${{ inputs.python-version }} |
| 19 | + cache: 'pip' |
| 20 | + cache-dependency-path: 'requirements*.txt' |
| 21 | + |
| 22 | + - name: Install PostgreSQL client tools |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + sudo apt-get update |
| 26 | + sudo apt-get install -y postgresql-client |
| 27 | +
|
| 28 | + - name: Wait for PostgreSQL to be ready |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + echo "Waiting for PostgreSQL to be ready..." |
| 32 | + for i in {1..30}; do |
| 33 | + if pg_isready -h localhost -p 5432 -U acapy_test; then |
| 34 | + echo "PostgreSQL is ready!" |
| 35 | + break |
| 36 | + fi |
| 37 | + echo "Attempt $i: PostgreSQL not ready yet, waiting..." |
| 38 | + sleep 2 |
| 39 | + done |
| 40 | +
|
| 41 | + # Final check |
| 42 | + if ! pg_isready -h localhost -p 5432 -U acapy_test; then |
| 43 | + echo "ERROR: PostgreSQL failed to become ready" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Verify PostgreSQL connection |
| 48 | + shell: bash |
| 49 | + env: |
| 50 | + PGPASSWORD: acapy_test_pass |
| 51 | + run: | |
| 52 | + echo "Testing PostgreSQL connection..." |
| 53 | + psql -h localhost -U acapy_test -d acapy_test_db -c "SELECT version();" |
| 54 | + echo "PostgreSQL connection verified!" |
| 55 | +
|
| 56 | + - name: Create additional test databases |
| 57 | + shell: bash |
| 58 | + env: |
| 59 | + PGPASSWORD: acapy_test_pass |
| 60 | + run: | |
| 61 | + echo "Creating additional test databases..." |
| 62 | + createdb -h localhost -U acapy_test test_kanon_db || true |
| 63 | + createdb -h localhost -U acapy_test test_dbstore_db || true |
| 64 | + createdb -h localhost -U acapy_test test_normalize || true |
| 65 | + createdb -h localhost -U acapy_test test_generic || true |
| 66 | + echo "Additional databases created" |
| 67 | +
|
| 68 | + - name: Grant database privileges |
| 69 | + shell: bash |
| 70 | + env: |
| 71 | + PGPASSWORD: acapy_test_pass |
| 72 | + run: | |
| 73 | + echo "Granting database privileges..." |
| 74 | + psql -h localhost -U acapy_test -d acapy_test_db -c "ALTER USER acapy_test WITH CREATEDB CREATEROLE;" |
| 75 | + echo "Privileges granted" |
| 76 | +
|
| 77 | + - name: Install project dependencies |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + pip install poetry |
| 81 | + poetry install --all-extras |
| 82 | +
|
| 83 | + - name: Run Kanon PostgreSQL Tests |
| 84 | + shell: bash |
| 85 | + env: |
| 86 | + POSTGRES_HOST: localhost |
| 87 | + POSTGRES_PORT: 5432 |
| 88 | + POSTGRES_USER: acapy_test |
| 89 | + POSTGRES_PASSWORD: acapy_test_pass |
| 90 | + POSTGRES_DB: acapy_test_db |
| 91 | + ENABLE_DBSTORE_TESTS: "1" |
| 92 | + LOG_LEVEL: WARNING |
| 93 | + run: | |
| 94 | + export POSTGRES_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" |
| 95 | +
|
| 96 | + echo "=========================================" |
| 97 | + echo "Running Kanon Integration Tests" |
| 98 | + echo "Database: ${POSTGRES_DB} on ${POSTGRES_HOST}:${POSTGRES_PORT}" |
| 99 | + echo "=========================================" |
| 100 | +
|
| 101 | + poetry run pytest \ |
| 102 | + acapy_agent/kanon/tests/ \ |
| 103 | + -v \ |
| 104 | + --cov=acapy_agent.kanon \ |
| 105 | + --cov-report term-missing \ |
| 106 | + --cov-report xml:./test-reports/kanon-postgres-coverage.xml \ |
| 107 | + --junitxml=./test-reports/kanon-postgres-junit.xml \ |
| 108 | + 2>&1 | tee kanon-postgres-tests.log |
| 109 | +
|
| 110 | + KANON_EXIT_CODE=${PIPESTATUS[0]} |
| 111 | +
|
| 112 | + echo "" |
| 113 | + echo "=========================================" |
| 114 | + echo "Kanon tests completed with exit code: $KANON_EXIT_CODE" |
| 115 | + echo "=========================================" |
| 116 | +
|
| 117 | + # Check for unawaited coroutines |
| 118 | + if grep -Eq "RuntimeWarning: coroutine .* was never awaited" kanon-postgres-tests.log; then |
| 119 | + echo "ERROR: Detected unawaited coroutine warning in Kanon tests" |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | +
|
| 123 | + if [ $KANON_EXIT_CODE -ne 0 ]; then |
| 124 | + echo "ERROR: Kanon PostgreSQL tests failed" |
| 125 | + exit $KANON_EXIT_CODE |
| 126 | + fi |
| 127 | +
|
| 128 | + - name: Run DBStore PostgreSQL Integration Tests |
| 129 | + shell: bash |
| 130 | + env: |
| 131 | + POSTGRES_HOST: localhost |
| 132 | + POSTGRES_PORT: 5432 |
| 133 | + POSTGRES_USER: acapy_test |
| 134 | + POSTGRES_PASSWORD: acapy_test_pass |
| 135 | + POSTGRES_DB: acapy_test_db |
| 136 | + ENABLE_DBSTORE_TESTS: "1" |
| 137 | + LOG_LEVEL: WARNING |
| 138 | + run: | |
| 139 | + export POSTGRES_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" |
| 140 | +
|
| 141 | + echo "=========================================" |
| 142 | + echo "Running DBStore PostgreSQL Integration Tests" |
| 143 | + echo "Database: ${POSTGRES_DB} on ${POSTGRES_HOST}:${POSTGRES_PORT}" |
| 144 | + echo "=========================================" |
| 145 | +
|
| 146 | + echo "Running core DBStore provisioning tests..." |
| 147 | +
|
| 148 | + # Test 1: PostgreSQL Normalized Provisioning (validates our provisioning bug fix) |
| 149 | + poetry run pytest \ |
| 150 | + -v \ |
| 151 | + --tb=short \ |
| 152 | + acapy_agent/database_manager/tests/dbstore/test_db_store_postgresql_normalized_provision.py::test_provision \ |
| 153 | + 2>&1 | tee -a dbstore-postgres-tests.log |
| 154 | +
|
| 155 | + PROVISION_TEST_1=$? |
| 156 | +
|
| 157 | + # Test 2: PostgreSQL Normalized Schema |
| 158 | + poetry run pytest \ |
| 159 | + -v \ |
| 160 | + --tb=short \ |
| 161 | + acapy_agent/database_manager/tests/dbstore/test_db_store_postgresql_normalized.py::test_provision \ |
| 162 | + 2>&1 | tee -a dbstore-postgres-tests.log |
| 163 | +
|
| 164 | + PROVISION_TEST_2=$? |
| 165 | +
|
| 166 | + # Test 3: PostgreSQL Generic Schema |
| 167 | + poetry run pytest \ |
| 168 | + -v \ |
| 169 | + --tb=short \ |
| 170 | + acapy_agent/database_manager/tests/dbstore/test_db_store_postgresql_generic.py::test_provision \ |
| 171 | + 2>&1 | tee -a dbstore-postgres-tests.log |
| 172 | +
|
| 173 | + PROVISION_TEST_3=$? |
| 174 | +
|
| 175 | + # Calculate overall exit code |
| 176 | + DBSTORE_EXIT_CODE=0 |
| 177 | + if [ $PROVISION_TEST_1 -ne 0 ] || [ $PROVISION_TEST_2 -ne 0 ] || [ $PROVISION_TEST_3 -ne 0 ]; then |
| 178 | + DBSTORE_EXIT_CODE=1 |
| 179 | + fi |
| 180 | +
|
| 181 | + # Generate coverage report for all tests |
| 182 | + poetry run pytest \ |
| 183 | + --cov=acapy_agent.database_manager \ |
| 184 | + --cov-report term-missing \ |
| 185 | + --cov-report xml:./test-reports/dbstore-postgres-coverage.xml \ |
| 186 | + --junitxml=./test-reports/dbstore-postgres-junit.xml \ |
| 187 | + --co \ |
| 188 | + acapy_agent/database_manager/tests/dbstore/test_db_store_postgresql*.py 2>/dev/null || true |
| 189 | +
|
| 190 | + echo "" |
| 191 | + echo "=========================================" |
| 192 | + echo "DBStore tests completed with exit code: $DBSTORE_EXIT_CODE" |
| 193 | + echo "=========================================" |
| 194 | +
|
| 195 | + # Check for unawaited coroutines |
| 196 | + if grep -Eq "RuntimeWarning: coroutine .* was never awaited" dbstore-postgres-tests.log; then |
| 197 | + echo "ERROR: Detected unawaited coroutine warning in DBStore tests" |
| 198 | + exit 1 |
| 199 | + fi |
| 200 | +
|
| 201 | + if [ $DBSTORE_EXIT_CODE -ne 0 ]; then |
| 202 | + echo "ERROR: DBStore PostgreSQL tests failed" |
| 203 | + exit $DBSTORE_EXIT_CODE |
| 204 | + fi |
| 205 | +
|
| 206 | + - name: Upload Kanon PostgreSQL Test Reports |
| 207 | + if: always() |
| 208 | + uses: actions/upload-artifact@v4 |
| 209 | + with: |
| 210 | + name: kanon-postgres-test-reports-${{ inputs.python-version }}-${{ inputs.os }} |
| 211 | + path: | |
| 212 | + test-reports/kanon-postgres-coverage.xml |
| 213 | + test-reports/kanon-postgres-junit.xml |
| 214 | + kanon-postgres-tests.log |
| 215 | +
|
| 216 | + - name: Upload DBStore PostgreSQL Test Reports |
| 217 | + if: always() |
| 218 | + uses: actions/upload-artifact@v4 |
| 219 | + with: |
| 220 | + name: dbstore-postgres-test-reports-${{ inputs.python-version }}-${{ inputs.os }} |
| 221 | + path: | |
| 222 | + test-reports/dbstore-postgres-coverage.xml |
| 223 | + test-reports/dbstore-postgres-junit.xml |
| 224 | + dbstore-postgres-tests.log |
| 225 | +
|
| 226 | + - name: Test Summary |
| 227 | + if: always() |
| 228 | + shell: bash |
| 229 | + run: | |
| 230 | + echo "=========================================" |
| 231 | + echo "PostgreSQL Integration Tests Summary" |
| 232 | + echo "=========================================" |
| 233 | + echo "✅ PostgreSQL service: Ready" |
| 234 | + echo "✅ Database connection: Verified" |
| 235 | + echo "✅ Kanon tests: Check artifacts" |
| 236 | + echo "✅ DBStore tests: Check artifacts" |
| 237 | + echo "=========================================" |
0 commit comments