From 0fad950a00c9eb9dc018f1ca7e280577a781e7c6 Mon Sep 17 00:00:00 2001 From: kgala2 Date: Wed, 2 Apr 2025 16:11:32 -0700 Subject: [PATCH 01/12] chore: add a broken assert --- tests/system/test_pymysql_connection.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 2748a8d7..ed62b1fe 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -124,3 +124,6 @@ def test_lazy_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + +def test_broken_test_reportss() -> None: + assert 1 == 2 \ No newline at end of file From 083d09be6f3fe6b6e491822d2f144d81fbb26153 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Wed, 2 Apr 2025 18:59:09 -0400 Subject: [PATCH 02/12] ci: add trusted-contribution.yml to trigger cloud build (#1265) --- .github/trusted-contribution.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/trusted-contribution.yml diff --git a/.github/trusted-contribution.yml b/.github/trusted-contribution.yml new file mode 100644 index 00000000..18580d06 --- /dev/null +++ b/.github/trusted-contribution.yml @@ -0,0 +1,28 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Trigger presubmit tests for trusted contributors +# https://github.com/googleapis/repo-automation-bots/tree/main/packages/trusted-contribution +# Install: https://github.com/apps/trusted-contributions-gcf + +trustedContributors: + - "dependabot[bot]" + - "renovate-bot" + - "renovate[bot]" + - "forking-renovate[bot]" + - "release-please[bot]" +annotations: + # Trigger Cloud Build tests + - type: comment + text: "/gcbrun" From bcde312811122f889206b9c10cac0a59c5a5d412 Mon Sep 17 00:00:00 2001 From: kgala2 Date: Fri, 4 Apr 2025 10:14:54 -0700 Subject: [PATCH 03/12] chore: remove broken test --- tests/system/test_pymysql_connection.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index ed62b1fe..2748a8d7 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -124,6 +124,3 @@ def test_lazy_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() - -def test_broken_test_reportss() -> None: - assert 1 == 2 \ No newline at end of file From b3b40fde19a702321b65cb7a7b234cf75ce1eb82 Mon Sep 17 00:00:00 2001 From: kgala2 Date: Wed, 9 Apr 2025 10:36:46 -0700 Subject: [PATCH 04/12] chore: add broken test --- tests/system/test_pymysql_connection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 2748a8d7..e8cd7879 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -124,3 +124,8 @@ def test_lazy_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + + +def test_broken_test_reports() -> None: + '''Expected to be failing but that's okay (testing schedule reporter)''' + assert 1 == 2 From 8f021cac5bd6ca1c0dc1468b9f1c85a7854249e5 Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 7 Apr 2025 15:25:43 -0400 Subject: [PATCH 05/12] test: add MySQL MCP tests (#1267) Add integration tests for MySQL for Cloud SQL's Managed Connection Pooling (MCP) --- .ci/cloudbuild.yaml | 109 +++++++++++++++--------- .github/workflows/tests.yml | 4 + tests/system/test_pymysql_connection.py | 20 ++++- tests/system/test_pymysql_iam_auth.py | 16 ++++ 4 files changed, 105 insertions(+), 44 deletions(-) diff --git a/.ci/cloudbuild.yaml b/.ci/cloudbuild.yaml index 9ed3add5..4c40d326 100644 --- a/.ci/cloudbuild.yaml +++ b/.ci/cloudbuild.yaml @@ -16,9 +16,32 @@ steps: - id: run integration tests name: python:${_VERSION} entrypoint: bash - env: + env: - "IP_TYPE=${_IP_TYPE}" - secretEnv: ["MYSQL_CONNECTION_NAME", "MYSQL_USER", "MYSQL_IAM_USER", "MYSQL_PASS", "MYSQL_DB", "POSTGRES_CONNECTION_NAME", "POSTGRES_USER", "POSTGRES_IAM_USER", "POSTGRES_PASS", "POSTGRES_DB", "POSTGRES_CAS_CONNECTION_NAME", "POSTGRES_CAS_PASS", "POSTGRES_CUSTOMER_CAS_CONNECTION_NAME", "POSTGRES_CUSTOMER_CAS_PASS", "POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME","SQLSERVER_CONNECTION_NAME", "SQLSERVER_USER", "SQLSERVER_PASS", "SQLSERVER_DB"] + secretEnv: + [ + "MYSQL_CONNECTION_NAME", + "MYSQL_USER", + "MYSQL_IAM_USER", + "MYSQL_PASS", + "MYSQL_DB", + "MYSQL_MCP_CONNECTION_NAME", + "MYSQL_MCP_PASS", + "POSTGRES_CONNECTION_NAME", + "POSTGRES_USER", + "POSTGRES_IAM_USER", + "POSTGRES_PASS", + "POSTGRES_DB", + "POSTGRES_CAS_CONNECTION_NAME", + "POSTGRES_CAS_PASS", + "POSTGRES_CUSTOMER_CAS_CONNECTION_NAME", + "POSTGRES_CUSTOMER_CAS_PASS", + "POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME", + "SQLSERVER_CONNECTION_NAME", + "SQLSERVER_USER", + "SQLSERVER_PASS", + "SQLSERVER_DB", + ] args: - "-c" - | @@ -26,48 +49,52 @@ steps: nox -s system-${_VERSION} availableSecrets: secretManager: - - versionName: 'projects/$PROJECT_ID/secrets/MYSQL_CONNECTION_NAME/versions/latest' - env: 'MYSQL_CONNECTION_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/MYSQL_USER/versions/latest' - env: 'MYSQL_USER' - - versionName: 'projects/$PROJECT_ID/secrets/CLOUD_BUILD_MYSQL_IAM_USER/versions/latest' - env: 'MYSQL_IAM_USER' - - versionName: 'projects/$PROJECT_ID/secrets/MYSQL_PASS/versions/latest' - env: 'MYSQL_PASS' - - versionName: 'projects/$PROJECT_ID/secrets/MYSQL_DB/versions/latest' - env: 'MYSQL_DB' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CONNECTION_NAME/versions/latest' - env: 'POSTGRES_CONNECTION_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_USER/versions/latest' - env: 'POSTGRES_USER' - - versionName: 'projects/$PROJECT_ID/secrets/CLOUD_BUILD_POSTGRES_IAM_USER/versions/latest' - env: 'POSTGRES_IAM_USER' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_PASS/versions/latest' - env: 'POSTGRES_PASS' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_DB/versions/latest' - env: 'POSTGRES_DB' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CAS_CONNECTION_NAME/versions/latest' - env: 'POSTGRES_CAS_CONNECTION_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CAS_PASS/versions/latest' - env: 'POSTGRES_CAS_PASS' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_CONNECTION_NAME/versions/latest' - env: 'POSTGRES_CUSTOMER_CAS_CONNECTION_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_PASS/versions/latest' - env: 'POSTGRES_CUSTOMER_CAS_PASS' - - versionName: 'projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME/versions/latest' - env: 'POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/SQLSERVER_CONNECTION_NAME/versions/latest' - env: 'SQLSERVER_CONNECTION_NAME' - - versionName: 'projects/$PROJECT_ID/secrets/SQLSERVER_USER/versions/latest' - env: 'SQLSERVER_USER' - - versionName: 'projects/$PROJECT_ID/secrets/SQLSERVER_PASS/versions/latest' - env: 'SQLSERVER_PASS' - - versionName: 'projects/$PROJECT_ID/secrets/SQLSERVER_DB/versions/latest' - env: 'SQLSERVER_DB' + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_CONNECTION_NAME/versions/latest" + env: "MYSQL_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_USER/versions/latest" + env: "MYSQL_USER" + - versionName: "projects/$PROJECT_ID/secrets/CLOUD_BUILD_MYSQL_IAM_USER/versions/latest" + env: "MYSQL_IAM_USER" + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_PASS/versions/latest" + env: "MYSQL_PASS" + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_DB/versions/latest" + env: "MYSQL_DB" + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_MCP_CONNECTION_NAME/versions/latest" + env: "MYSQL_MCP_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/MYSQL_MCP_PASS/versions/latest" + env: "MYSQL_MCP_PASS" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CONNECTION_NAME/versions/latest" + env: "POSTGRES_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_USER/versions/latest" + env: "POSTGRES_USER" + - versionName: "projects/$PROJECT_ID/secrets/CLOUD_BUILD_POSTGRES_IAM_USER/versions/latest" + env: "POSTGRES_IAM_USER" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_PASS/versions/latest" + env: "POSTGRES_PASS" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_DB/versions/latest" + env: "POSTGRES_DB" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CAS_CONNECTION_NAME/versions/latest" + env: "POSTGRES_CAS_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CAS_PASS/versions/latest" + env: "POSTGRES_CAS_PASS" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_CONNECTION_NAME/versions/latest" + env: "POSTGRES_CUSTOMER_CAS_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_PASS/versions/latest" + env: "POSTGRES_CUSTOMER_CAS_PASS" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME/versions/latest" + env: "POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME" + - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_CONNECTION_NAME/versions/latest" + env: "SQLSERVER_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_USER/versions/latest" + env: "SQLSERVER_USER" + - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_PASS/versions/latest" + env: "SQLSERVER_PASS" + - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_DB/versions/latest" + env: "SQLSERVER_DB" substitutions: _VERSION: ${_VERSION} _IP_TYPE: ${_IP_TYPE} - + options: dynamicSubstitutions: true pool: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b8e6eb58..755ad569 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -72,6 +72,8 @@ jobs: MYSQL_IAM_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER_IAM_PYTHON MYSQL_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS MYSQL_DB:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB + MYSQL_MCP_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_MCP_CONNECTION_NAME + MYSQL_MCP_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_MCP_PASS POSTGRES_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME POSTGRES_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER POSTGRES_IAM_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_PYTHON @@ -94,6 +96,8 @@ jobs: MYSQL_IAM_USER: "${{ steps.secrets.outputs.MYSQL_IAM_USER }}" MYSQL_PASS: "${{ steps.secrets.outputs.MYSQL_PASS }}" MYSQL_DB: "${{ steps.secrets.outputs.MYSQL_DB }}" + MYSQL_MCP_CONNECTION_NAME: "${{ steps.secrets.outputs.MYSQL_MCP_CONNECTION_NAME }}" + MYSQL_MCP_PASS: "${{ steps.secrets.outputs.MYSQL_MCP_PASS }}" POSTGRES_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}" POSTGRES_USER: "${{ steps.secrets.outputs.POSTGRES_USER }}" POSTGRES_IAM_USER: "${{ steps.secrets.outputs.POSTGRES_IAM_USER }}" diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index e8cd7879..f5dd8a1e 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -126,6 +126,20 @@ def test_lazy_pymysql_connection() -> None: connector.close() -def test_broken_test_reports() -> None: - '''Expected to be failing but that's okay (testing schedule reporter)''' - assert 1 == 2 +def test_MCP_pymysql_connection() -> None: + """Basic test to get time from database using MCP enabled instance.""" + inst_conn_name = os.environ["MYSQL_MCP_CONNECTION_NAME"] + user = os.environ["MYSQL_USER"] + password = os.environ["MYSQL_MCP_PASS"] + db = os.environ["MYSQL_DB"] + ip_type = os.environ.get("IP_TYPE", "public") + + engine, connector = create_sqlalchemy_engine( + inst_conn_name, user, password, db, ip_type + ) + with engine.connect() as conn: + time = conn.execute(sqlalchemy.text("SELECT NOW()")).fetchone() + conn.commit() + curr_time = time[0] + assert type(curr_time) is datetime + connector.close() diff --git a/tests/system/test_pymysql_iam_auth.py b/tests/system/test_pymysql_iam_auth.py index 39af5c71..da676e66 100644 --- a/tests/system/test_pymysql_iam_auth.py +++ b/tests/system/test_pymysql_iam_auth.py @@ -113,3 +113,19 @@ def test_lazy_pymysql_iam_authn_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + + +def test_MCP_pymysql_iam_authn_connection() -> None: + """Basic test to get time from database using MCP enabled instance.""" + inst_conn_name = os.environ["MYSQL_MCP_CONNECTION_NAME"] + user = os.environ["MYSQL_IAM_USER"] + db = os.environ["MYSQL_DB"] + ip_type = os.environ.get("IP_TYPE", "public") + + engine, connector = create_sqlalchemy_engine(inst_conn_name, user, db, ip_type) + with engine.connect() as conn: + time = conn.execute(sqlalchemy.text("SELECT NOW()")).fetchone() + conn.commit() + curr_time = time[0] + assert type(curr_time) is datetime + connector.close() From 1d4dd881c355893da4cb1094ed15d8135122e00c Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 7 Apr 2025 15:29:50 -0400 Subject: [PATCH 06/12] test: add Postgres MCP tests (#1266) Add integration tests for Postgres for Cloud SQL's Managed Connection Pooling (MCP). --- .ci/cloudbuild.yaml | 6 ++++++ .github/workflows/tests.yml | 4 ++++ tests/system/test_asyncpg_connection.py | 26 +++++++++++++++++++++++++ tests/system/test_pg8000_connection.py | 19 ++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/.ci/cloudbuild.yaml b/.ci/cloudbuild.yaml index 4c40d326..e31e8beb 100644 --- a/.ci/cloudbuild.yaml +++ b/.ci/cloudbuild.yaml @@ -37,6 +37,8 @@ steps: "POSTGRES_CUSTOMER_CAS_CONNECTION_NAME", "POSTGRES_CUSTOMER_CAS_PASS", "POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME", + "POSTGRES_MCP_CONNECTION_NAME", + "POSTGRES_MCP_PASS", "SQLSERVER_CONNECTION_NAME", "SQLSERVER_USER", "SQLSERVER_PASS", @@ -83,6 +85,10 @@ availableSecrets: env: "POSTGRES_CUSTOMER_CAS_PASS" - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME/versions/latest" env: "POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_MCP_CONNECTION_NAME/versions/latest" + env: "POSTGRES_MCP_CONNECTION_NAME" + - versionName: "projects/$PROJECT_ID/secrets/POSTGRES_MCP_PASS/versions/latest" + env: "POSTGRES_MCP_PASS" - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_CONNECTION_NAME/versions/latest" env: "SQLSERVER_CONNECTION_NAME" - versionName: "projects/$PROJECT_ID/secrets/SQLSERVER_USER/versions/latest" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 755ad569..8e5d0b00 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,6 +84,8 @@ jobs: POSTGRES_CUSTOMER_CAS_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CUSTOMER_CAS_CONNECTION_NAME POSTGRES_CUSTOMER_CAS_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CUSTOMER_CAS_PASS POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME + POSTGRES_MCP_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_MCP_CONNECTION_NAME + POSTGRES_MCP_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_MCP_PASS SQLSERVER_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_CONNECTION_NAME SQLSERVER_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_USER SQLSERVER_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_PASS @@ -108,6 +110,8 @@ jobs: POSTGRES_CUSTOMER_CAS_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CUSTOMER_CAS_CONNECTION_NAME }}" POSTGRES_CUSTOMER_CAS_PASS: "${{ steps.secrets.outputs.POSTGRES_CUSTOMER_CAS_PASS }}" POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME: "${{ steps.secrets.outputs.POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME }}" + POSTGRES_MCP_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_MCP_CONNECTION_NAME }}" + POSTGRES_MCP_PASS: "${{ steps.secrets.outputs.POSTGRES_MCP_PASS }}" SQLSERVER_CONNECTION_NAME: "${{ steps.secrets.outputs.SQLSERVER_CONNECTION_NAME }}" SQLSERVER_USER: "${{ steps.secrets.outputs.SQLSERVER_USER }}" SQLSERVER_PASS: "${{ steps.secrets.outputs.SQLSERVER_PASS }}" diff --git a/tests/system/test_asyncpg_connection.py b/tests/system/test_asyncpg_connection.py index d7602e53..1aae1f7e 100644 --- a/tests/system/test_asyncpg_connection.py +++ b/tests/system/test_asyncpg_connection.py @@ -35,6 +35,7 @@ async def create_sqlalchemy_engine( ip_type: str = "public", refresh_strategy: str = "background", resolver: Union[type[DefaultResolver], type[DnsResolver]] = DefaultResolver, + **kwargs: Any, ) -> tuple[sqlalchemy.ext.asyncio.engine.AsyncEngine, Connector]: """Creates a connection pool for a Cloud SQL instance and returns the pool and the connector. Callers are responsible for closing the pool and the @@ -92,6 +93,7 @@ async def create_sqlalchemy_engine( password=password, db=db, ip_type=ip_type, # can be "public", "private" or "psc" + **kwargs, # additional asyncpg connection args ), execution_options={"isolation_level": "AUTOCOMMIT"}, ) @@ -220,6 +222,30 @@ async def test_custom_SAN_with_dns_sqlalchemy_connection_with_asyncpg() -> None: await connector.close_async() +async def test_MCP_sqlalchemy_connection_with_asyncpg() -> None: + """Basic test to get time from database using MCP enabled instance.""" + inst_conn_name = os.environ["POSTGRES_MCP_CONNECTION_NAME"] + user = os.environ["POSTGRES_USER"] + password = os.environ["POSTGRES_MCP_PASS"] + db = os.environ["POSTGRES_DB"] + ip_type = os.environ.get("IP_TYPE", "public") + + pool, connector = await create_sqlalchemy_engine( + inst_conn_name, + user, + password, + db, + ip_type, + statement_cache_size=0, + ) + + async with pool.connect() as conn: + res = (await conn.execute(sqlalchemy.text("SELECT 1"))).fetchone() + assert res[0] == 1 + + await connector.close_async() + + async def test_connection_with_asyncpg() -> None: """Basic test to get time from database.""" inst_conn_name = os.environ["POSTGRES_CONNECTION_NAME"] diff --git a/tests/system/test_pg8000_connection.py b/tests/system/test_pg8000_connection.py index 42a8d989..c7074b0c 100644 --- a/tests/system/test_pg8000_connection.py +++ b/tests/system/test_pg8000_connection.py @@ -191,3 +191,22 @@ def test_custom_SAN_with_dns_pg8000_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + + +def test_MCP_pg8000_connection() -> None: + """Basic test to get time from database using MCP enabled instance.""" + inst_conn_name = os.environ["POSTGRES_MCP_CONNECTION_NAME"] + user = os.environ["POSTGRES_USER"] + password = os.environ["POSTGRES_MCP_PASS"] + db = os.environ["POSTGRES_DB"] + ip_type = os.environ.get("IP_TYPE", "public") + + engine, connector = create_sqlalchemy_engine( + inst_conn_name, user, password, db, ip_type + ) + with engine.connect() as conn: + time = conn.execute(sqlalchemy.text("SELECT NOW()")).fetchone() + conn.commit() + curr_time = time[0] + assert type(curr_time) is datetime + connector.close() From c251d7b6c6a179c5df33029ffd4a722da0bc43e8 Mon Sep 17 00:00:00 2001 From: kgala2 Date: Wed, 2 Apr 2025 16:11:32 -0700 Subject: [PATCH 07/12] chore: add a broken assert --- tests/system/test_pymysql_connection.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index f5dd8a1e..3d532e35 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -143,3 +143,7 @@ def test_MCP_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + +def test_broken_test_reports() -> None: + '''This test breaks but that's expected''' + assert 1 == 2 From 35c65de31cba843e07fc62e79d0304883ee96f6c Mon Sep 17 00:00:00 2001 From: kgala2 Date: Fri, 4 Apr 2025 10:14:54 -0700 Subject: [PATCH 08/12] chore: remove broken test --- tests/system/test_pymysql_connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 3d532e35..179c4f03 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -144,6 +144,7 @@ def test_MCP_pymysql_connection() -> None: assert type(curr_time) is datetime connector.close() + def test_broken_test_reports() -> None: '''This test breaks but that's expected''' assert 1 == 2 From 36588206684f5ce1d522cc0625f004835c30349e Mon Sep 17 00:00:00 2001 From: Jack Wotherspoon Date: Mon, 7 Apr 2025 15:25:43 -0400 Subject: [PATCH 09/12] test: add MySQL MCP tests (#1267) Add integration tests for MySQL for Cloud SQL's Managed Connection Pooling (MCP) --- tests/system/test_pymysql_connection.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 179c4f03..f5dd8a1e 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -143,8 +143,3 @@ def test_MCP_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() - - -def test_broken_test_reports() -> None: - '''This test breaks but that's expected''' - assert 1 == 2 From 07fb11353d9e3b6d9a74f8bfcf20d1d30ce69f2f Mon Sep 17 00:00:00 2001 From: kgala2 Date: Wed, 2 Apr 2025 16:11:32 -0700 Subject: [PATCH 10/12] chore: add a broken assert --- tests/system/test_pymysql_connection.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index f5dd8a1e..3d532e35 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -143,3 +143,7 @@ def test_MCP_pymysql_connection() -> None: curr_time = time[0] assert type(curr_time) is datetime connector.close() + +def test_broken_test_reports() -> None: + '''This test breaks but that's expected''' + assert 1 == 2 From c19b39839b59d829c25a1d3692c38efbe5ee7a63 Mon Sep 17 00:00:00 2001 From: kgala2 Date: Fri, 4 Apr 2025 10:14:54 -0700 Subject: [PATCH 11/12] chore: remove broken test --- tests/system/test_pymysql_connection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 3d532e35..179c4f03 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -144,6 +144,7 @@ def test_MCP_pymysql_connection() -> None: assert type(curr_time) is datetime connector.close() + def test_broken_test_reports() -> None: '''This test breaks but that's expected''' assert 1 == 2 From 1c98f3fe460d337a97c59e718ddb4209de7a322f Mon Sep 17 00:00:00 2001 From: kgala2 Date: Wed, 9 Apr 2025 11:22:21 -0700 Subject: [PATCH 12/12] chore: lintify test_pymysql_connection.py --- tests/system/test_pymysql_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/test_pymysql_connection.py b/tests/system/test_pymysql_connection.py index 179c4f03..d6aec49b 100644 --- a/tests/system/test_pymysql_connection.py +++ b/tests/system/test_pymysql_connection.py @@ -146,5 +146,5 @@ def test_MCP_pymysql_connection() -> None: def test_broken_test_reports() -> None: - '''This test breaks but that's expected''' + """This test breaks but that's expected""" assert 1 == 2