Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
python-version: '3.13'
python-version: '3.14'

- name: Run Hyperdrive binding tests
working-directory: packages/runtime-sdk
Expand Down
13 changes: 12 additions & 1 deletion packages/runtime-sdk/tests/bindings-test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
name = "bindings-test"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["pytest", "pytest-asyncio<1.2.0", "pg8000", "pymysql", "cryptography", "testlib"]
dependencies = [
"pytest",
"pytest-asyncio<1.2.0",
# These are for hyperdrive tests
"pg8000",
"pymysql",
"aiomysql",
"psycopg[binary]; python_version >= '3.14'",
"asyncpg; python_version >= '3.14'",
"cryptography",
"testlib",
]

[tool.uv.sources]
testlib = { path = "../testlib/dist/testlib-0.0.0-py3-none-any.whl" }
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import sys

import aiomysql
import pymysql
import pytest
from conftest import unique_table_name
Expand Down Expand Up @@ -58,6 +59,26 @@ async def test_connect(env):
conn.close()


@pytest.mark.asyncio
async def test_connect_aiomysql(env):
hd = env.HYPERDRIVE_MYSQL
conn = await aiomysql.connect(
host=hd.host,
port=int(hd.port),
user=hd.user,
password=hd.password,
db=hd.database,
# Hyperdrive terminates TLS to the origin, so this hop is plaintext.
ssl=None,
)
try:
async with conn.cursor() as cur:
await cur.execute("SELECT %s", (1,))
assert await cur.fetchone() == (1,)
finally:
await conn.ensure_closed()


@pytest.mark.asyncio
async def test_create_insert_select(env):
conn = _connect(env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,71 @@ async def test_connect(env):
conn.close()


@pytest.mark.asyncio
async def test_connect_psycopg(env):
import psycopg # noqa: PLC0415

assert psycopg.pq.__impl__ == "binary"
hd = env.HYPERDRIVE_PG
with psycopg.connect(
Comment thread
ryanking13 marked this conversation as resolved.
host=hd.host,
port=int(hd.port),
user=hd.user,
password=hd.password,
dbname=hd.database,
# Hyperdrive terminates TLS to the origin, so this hop is plaintext.
sslmode="disable",
) as conn:
with conn.cursor() as cur:
cur.execute("SELECT %s", (1,))
assert cur.fetchone() == (1,)


@pytest.mark.asyncio
async def test_asyncpg_crud(env):
import asyncpg # noqa: PLC0415

hd = env.HYPERDRIVE_PG
conn = await asyncpg.connect(
host=hd.host,
port=int(hd.port),
user=hd.user,
password=hd.password,
database=hd.database,
# Hyperdrive terminates TLS to the origin, so this hop is plaintext.
ssl=False,
)
table = unique_table_name()
try:
await conn.execute(
f"CREATE TABLE {table} (id SERIAL PRIMARY KEY, name TEXT, value INT)"
)
await conn.execute(
f"INSERT INTO {table} (name, value) VALUES ($1, $2)", "alpha", 1
)

row = await conn.fetchrow(
f"SELECT name, value FROM {table} WHERE name = $1", "alpha"
)
assert tuple(row) == ("alpha", 1)

await conn.execute(
f"UPDATE {table} SET value = $1 WHERE name = $2", 11, "alpha"
)
assert (
await conn.fetchval(f"SELECT value FROM {table} WHERE name = $1", "alpha")
== 11
)

await conn.execute(f"DELETE FROM {table} WHERE name = $1", "alpha")
assert await conn.fetchval(f"SELECT COUNT(*) FROM {table}") == 0
finally:
try:
await conn.execute(f"DROP TABLE IF EXISTS {table}")
finally:
await conn.close()


@pytest.mark.asyncio
async def test_create_insert_select(env):
conn = _connect(env)
Expand Down
Loading