This is an automated email from the ASF dual-hosted git repository. sciabarracom pushed a commit to branch 0.9.0 in repository https://gitbox.apache.org/repos/asf/openserverless-testing.git
commit d931580d27c97ce38e72c005e0cd25c5ee43efac Author: Build OpenServerless <[email protected]> AuthorDate: Mon Sep 7 19:49:14 2026 +0000 fixes to the tests --- test-runtimes/javascript/{minio.js => seaweed.js} | 0 test-runtimes/manifest.yaml | 8 ++-- test-runtimes/python/postgres.py | 50 ++++++++++++++++------- test-runtimes/python/{minio.py => seaweed.py} | 0 tests/14-runtime-testing.sh | 3 +- tests/all.sh | 4 +- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/test-runtimes/javascript/minio.js b/test-runtimes/javascript/seaweed.js similarity index 100% rename from test-runtimes/javascript/minio.js rename to test-runtimes/javascript/seaweed.js diff --git a/test-runtimes/manifest.yaml b/test-runtimes/manifest.yaml index 0b27435..1d9802d 100644 --- a/test-runtimes/manifest.yaml +++ b/test-runtimes/manifest.yaml @@ -36,8 +36,8 @@ packages: function: javascript/mongodb.js postgres: function: javascript/postgres.js - minio: - function: javascript/minio.js + seaweed: + function: javascript/seaweed.js python: inputs: redis_url: ${REDIS_URL} @@ -59,5 +59,5 @@ packages: function: python/mongodb.py postgres: function: python/postgres.py - minio: - function: python/minio.py + seaweed: + function: python/seaweed.py diff --git a/test-runtimes/python/postgres.py b/test-runtimes/python/postgres.py index 263c3d4..d3905d6 100644 --- a/test-runtimes/python/postgres.py +++ b/test-runtimes/python/postgres.py @@ -15,33 +15,50 @@ # specific language governing permissions and limitations # under the License. # -import psycopg +import pg8000.dbapi + +from urllib.parse import urlparse, unquote + +def connect(postgres_url): + """ + Opens a pg8000 connection from the given postgres URL. pg8000 takes + connection arguments as keywords, so the URL is parsed here. + """ + url = urlparse(postgres_url) + return pg8000.dbapi.connect( + host=url.hostname, + port=url.port or 5432, + user=unquote(url.username) if url.username else None, + password=unquote(url.password) if url.password else None, + database=url.path.lstrip("/") or None, + ) def main(args): response = {"body": {}} - with psycopg.connect(args.get("postgres_url")) as conn: - + conn = connect(args.get("postgres_url")) + try: # Open a cursor to perform database operations - with conn.cursor() as cur: - cur.execute("""CREATE SCHEMA IF NOT EXISTS openserverless; - SET search_path TO openserverless; - """) + cur = conn.cursor() + try: + # pg8000 uses the extended query protocol: one statement per execute() + cur.execute("CREATE SCHEMA IF NOT EXISTS openserverless") + cur.execute("SET search_path TO openserverless") # Execute a command: this creates a new table + cur.execute('CREATE EXTENSION IF NOT EXISTS "pgcrypto"') cur.execute(""" - CREATE EXTENSION IF NOT EXISTS "pgcrypto"; CREATE TABLE IF NOT EXISTS openserverless_table ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - message varchar(100) - ); + message varchar(100) + ) """) - # Pass data to fill a query placeholders and let Psycopg perform + # Pass data to fill a query placeholders and let pg8000 perform # the correct conversion (no SQL injections!) - cur.execute("INSERT INTO openserverless_table(message) VALUES(%(message)s)",{"message":"OpenServerless Postgres is up and running!"}) - # Make the changes to the database persistent + cur.execute("INSERT INTO openserverless_table(message) VALUES(%s)", + ("OpenServerless Postgres is up and running!",)) # Query the database and obtain data as Python objects. cur.execute("SELECT message FROM openserverless_table") @@ -51,6 +68,11 @@ def main(args): cur.execute("DROP SCHEMA openserverless CASCADE") response["body"] = record + # Make the changes to the database persistent conn.commit() + finally: + cur.close() + finally: + conn.close() - return response \ No newline at end of file + return response diff --git a/test-runtimes/python/minio.py b/test-runtimes/python/seaweed.py similarity index 100% rename from test-runtimes/python/minio.py rename to test-runtimes/python/seaweed.py diff --git a/tests/14-runtime-testing.sh b/tests/14-runtime-testing.sh index ba5c87c..a568673 100755 --- a/tests/14-runtime-testing.sh +++ b/tests/14-runtime-testing.sh @@ -61,6 +61,7 @@ export POSTGRES_URL=$(ops -config POSTGRES_URL) test_invoke() { ACT="$1" RES="$2" + echo TEST $ACT for i in 1 2 3 4 5 do echo "Attempt #$i" @@ -102,7 +103,7 @@ else echo FAIL JS POSTGRES; exit 1 fi #if ops -wsk action invoke javascript/minio -r| grep "$user-data" -if test_invoke javascript/minio "$user-data" +if test_invoke javascript/seaweed "$user-data" then echo SUCCESS JS S3; else echo FAIL JS S3; exit 1 fi diff --git a/tests/all.sh b/tests/all.sh index 8505f80..b84578c 100755 --- a/tests/all.sh +++ b/tests/all.sh @@ -46,7 +46,7 @@ esac cd "$SCRIPT_DIR" rm -f _results _log collect() { - if "$@" 2>&1 | tee _log + if "$@" 2>&1 then echo SUCCESS "$1" >> _results else @@ -91,7 +91,7 @@ collect ./4b-sys-postgres.sh echo "##############################################" echo "# #" -echo "# TESTING SEAWEEDFS $TYPE #" +echo "# TESTING SEAWEEDFS $TYPE #" echo "# #" echo "##############################################" collect ./5-sys-seaweedfs.sh
