|
10 | 10 | from ec2instanceconnectcli.EC2InstanceConnectKey import EC2InstanceConnectKey
|
11 | 11 | from time import sleep
|
12 | 12 | import paramiko
|
| 13 | +from pathlib import Path |
13 | 14 |
|
14 | 15 | # if EXECUTION_ID is not set, use a default value that includes the user and hostname
|
15 | 16 | RUN_ID = os.environ.get(
|
|
143 | 144 | """
|
144 | 145 | anon_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTYyMjQ5NjYsImV4cCI6MjAxMTgwMDk2Nn0.QW95aRPA-4QuLzuvaIeeoFKlJP9J2hvAIpJ3WJ6G5zo"
|
145 | 146 | service_role_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY5NjIyNDk2NiwiZXhwIjoyMDExODAwOTY2fQ.Om7yqv15gC3mLGitBmvFRB3M4IsLsX9fXzTQnFM7lu0"
|
146 |
| -EXPECTED_PGBOUNCER_VERSION = "1.24.1" |
147 | 147 | supabase_admin_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFhYWFhYWFhYWFhYWFhYWFhYWFhIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNjk2MjI0OTY2LCJleHAiOjIwMTE4MDA5NjZ9.jrD3j2rBWiIx0vhVZzd1CXFv7qkAP392nBMadvXxk1c"
|
| 148 | + |
| 149 | + |
| 150 | +def load_expected_pgbouncer_version() -> str: |
| 151 | + repo_root = Path(__file__).resolve().parent.parent |
| 152 | + ansible_vars = repo_root / "ansible" / "vars.yml" |
| 153 | + if ansible_vars.exists(): |
| 154 | + with ansible_vars.open() as f: |
| 155 | + for raw_line in f: |
| 156 | + line = raw_line.strip() |
| 157 | + if line.startswith("pgbouncer_release:"): |
| 158 | + return line.split(":", 1)[1].strip().strip('"') |
| 159 | + |
| 160 | + nix_file = repo_root / "nix" / "pgbouncer.nix" |
| 161 | + if nix_file.exists(): |
| 162 | + with nix_file.open() as f: |
| 163 | + for raw_line in f: |
| 164 | + line = raw_line.strip() |
| 165 | + if line.startswith("version ="): |
| 166 | + value = line.split("=", 1)[1].strip() |
| 167 | + return value.strip(";").strip('"') |
| 168 | + |
| 169 | + raise RuntimeError( |
| 170 | + "Could not determine expected PgBouncer version from configuration files" |
| 171 | + ) |
| 172 | + |
| 173 | + |
| 174 | +EXPECTED_PGBOUNCER_VERSION = load_expected_pgbouncer_version() |
| 175 | +PGBOUNCER_BINARY = "/nix/var/nix/profiles/per-user/pgbouncer/profile/bin/pgbouncer" |
148 | 176 | init_json_content = f"""
|
149 | 177 | {{
|
150 | 178 | "jwt_secret": "my_jwt_secret_which_is_not_so_secret",
|
@@ -624,39 +652,6 @@ def test_libpq5_version(host):
|
624 | 652 | print("✓ libpq5 version is >= 14")
|
625 | 653 |
|
626 | 654 |
|
627 |
| -def test_pgbouncer_version(host): |
628 |
| - """Ensure the PgBouncer binary version matches what we build.""" |
629 |
| - result = run_ssh_command(host["ssh"], "pgbouncer --version") |
630 |
| - assert result["succeeded"], f"Failed to get PgBouncer version: {result['stderr']}" |
631 |
| - |
632 |
| - output = result["stdout"].strip() |
633 |
| - import re |
634 |
| - |
635 |
| - match = re.search(r"PgBouncer(?: version)? ([0-9.]+)", output) |
636 |
| - assert match is not None, f"Could not parse PgBouncer version from output: {output}" |
637 |
| - installed_version = match.group(1) |
638 |
| - assert ( |
639 |
| - installed_version == EXPECTED_PGBOUNCER_VERSION |
640 |
| - ), f"PgBouncer version mismatch: expected {EXPECTED_PGBOUNCER_VERSION}, got {installed_version}" |
641 |
| - |
642 |
| - |
643 |
| -def test_pgbouncer_supports_prepared_statements(host): |
644 |
| - """Verify prepared statements can be created and executed through PgBouncer.""" |
645 |
| - command = ( |
646 |
| - "sudo -u postgres psql -p 6543 -d postgres " |
647 |
| - "-v ON_ERROR_STOP=1 " |
648 |
| - '-c "PREPARE test_plan AS SELECT 1;" ' |
649 |
| - '-c "EXECUTE test_plan;" ' |
650 |
| - '-c "DEALLOCATE test_plan;"' |
651 |
| - ) |
652 |
| - |
653 |
| - result = run_ssh_command(host["ssh"], command) |
654 |
| - assert result["succeeded"], ( |
655 |
| - "Prepared statements are not working through PgBouncer: " |
656 |
| - f"{result['stderr'] or result['stdout']}" |
657 |
| - ) |
658 |
| - |
659 |
| - |
660 | 655 | def test_postgrest_read_only_session_attrs(host):
|
661 | 656 | """Test PostgREST with target_session_attrs=read-only and check for session errors."""
|
662 | 657 | # First, check if PostgreSQL is configured for read-only mode
|
|
0 commit comments