branch: elpa/pg commit 71f958e76f3873c323014cbce436225fce9a00bc Author: Eric Marsden <eric.mars...@risk-engineering.org> Commit: Eric Marsden <eric.mars...@risk-engineering.org>
Tests: add workarounds for CrateDB, CockroachDB and CedarDB --- test/Makefile | 124 ++++++++++++++++++++++++++++---------------------------- test/test-pg.el | 59 ++++++++++++++++----------- 2 files changed, 98 insertions(+), 85 deletions(-) diff --git a/test/Makefile b/test/Makefile index d68a463d694..24f72544b07 100644 --- a/test/Makefile +++ b/test/Makefile @@ -591,27 +591,6 @@ test-cedardb: test-pg.el ${DOCKER} stop cedardb -# https://docs.geldata.com/reference/running/deployment/docker -# https://docs.geldata.com/reference/running/configuration -# https://hub.docker.com/r/geldata/gel -# https://github.com/geldata/gel -# -# We don't bother detecting this as a specific PostgreSQL variant, because the SQL syntax it accepts -# is too different from standard PostgreSQL (no support for CREATE, for DROP, for EXPLAIN...) -test-geldata: test-pg.el - ${DOCKER} run --rm --name geldata \ - --pull=newer \ - --publish 127.0.0.1:5656:5656 \ - -e GEL_SERVER_USER=pgeltestuser \ - -e GEL_SERVER_PASSWORD=pgeltest \ - -e GEL_SERVER_PORT=5656 \ - -e GEL_SERVER_SECURITY=insecure_dev_mode \ - -d docker.io/geldata/gel:nightly - sleep 20 - PGURI="postgresql://pgeltestuser:pgeltest@127.0.0.1:5656/edgedb?sslmode=require" $(MAKE) test-tls - ${DOCKER} stop geldata - - # https://hub.docker.com/r/pgedge/pgedge # https://github.com/pgEdge/pgedge-docker # @@ -749,8 +728,8 @@ test-readyset: test-pg.el # implement the BYTEA, JSON, JSONB and HSTORE types, doesn't support COPY, doesn't support Unicode # identifiers. # -# It even seems to lose some INSERT statements (failing in pg-test-insert on the count of rows -# inserted into the row_count table). +# CrateDB is fantastically slow on some CREATE TABLE statements that include a VARCHAR(n) column, +# which is why we set the read_timeout to a high value. # # https://hub.docker.com/_/crate/ # https://github.com/crate/docker-crate/blob/master/Dockerfile @@ -763,7 +742,7 @@ test-cratedb: test-pg.el -e CRATE_HEAP_SIZE=1g \ -d docker.io/crate -Cnetwork.host=127.0.0.1 -Cdiscovery.type=single-node -Cpsql.port=5789 sleep 5 - PGURI=postgresql://crate@127.0.0.1:5789/postgres $(MAKE) test + PGURI="postgresql://crate@127.0.0.1:5789/postgres?read_timeout=1000" $(MAKE) test ${DOCKER} stop cratedb @@ -808,45 +787,25 @@ test-questdb: test-pg.el ${DOCKER} stop questdb -# Yugabyte 2.25 is based on PostgreSQL 15.2. This works very well, including the HSTORE and pgvector -# extensions. The sequence test fails (SELECT last_value FROM pg_sequences). Some more recent SQL -# evolutions such as "INTEGER GENERATED ALWAYS AS expression STORED" are not supported. -# LISTEN/NOTIFY is not supported. -# -# TODO: test YSQL_PASSWORD -# https://docs.yugabyte.com/preview/reference/configuration/yugabyted/ -test-yugabyte: test-pg.el - ${DOCKER} run --rm --name yugabyte \ - --pull=newer \ - --net host \ - -e YSQL_DB=pgeltestdb \ - -e YSQL_USER=pgeltestuser \ - -d docker.io/yugabytedb/yugabyte:latest \ - bin/yugabyted start \ - --ysql_port 5493 \ - --advertise_address 127.0.0.1 \ - --base_dir=/tmp \ - --background=false - sleep 10 - PGURI=postgresql://pgeltestuser@127.0.0.1:5493/pgeltestdb $(MAKE) test - ${DOCKER} stop yugabyte - - -# https://github.com/ApsaraDB/PolarDB-for-PostgreSQL from Alibaba Cloud +# https://docs.geldata.com/reference/running/deployment/docker +# https://docs.geldata.com/reference/running/configuration +# https://hub.docker.com/r/geldata/gel +# https://github.com/geldata/gel # -# Note: primary runs on $POLARDB_PORT, replicas on ${POLARDB_PORT}+1 and ${POLARDB_PORT}+2 -# We don't seem to be able to set POLARDB_DATABASE or equivalent -test-polardb: test-pg.el - ${DOCKER} run --rm --name polardb \ +# We don't bother detecting this as a specific PostgreSQL variant, because the SQL syntax it accepts +# is too different from standard PostgreSQL (no support for CREATE, for DROP, for EXPLAIN...) +test-geldata: test-pg.el + ${DOCKER} run --rm --name geldata \ --pull=newer \ - --publish 127.0.0.1:5998:5998 \ - -e POLARDB_PORT=5998 \ - -e POLARDB_USER=pgeltestuser \ - -e POLARDB_PASSWORD=pgeltest \ - -d docker.io/polardb/polardb_pg_local_instance:15 - sleep 10 - PGURI=postgresql://pgeltestuser:pgeltest@127.0.0.1:5998/postgres $(MAKE) test - ${DOCKER} stop polardb + --publish 127.0.0.1:5656:5656 \ + -e GEL_SERVER_USER=pgeltestuser \ + -e GEL_SERVER_PASSWORD=pgeltest \ + -e GEL_SERVER_PORT=5656 \ + -e GEL_SERVER_SECURITY=insecure_dev_mode \ + -d docker.io/geldata/gel:nightly + sleep 20 + PGURI="postgresql://pgeltestuser:pgeltest@127.0.0.1:5656/edgedb?sslmode=require" $(MAKE) test-tls + ${DOCKER} stop geldata # Materialize (here the "Materialize emulator" running in Docker). This proprietary differential @@ -982,6 +941,47 @@ test-ydb: test-pg.el ${DOCKER} stop ydb +# Yugabyte 2.25 is based on PostgreSQL 15.2. This works very well, including the HSTORE and pgvector +# extensions. The sequence test fails (SELECT last_value FROM pg_sequences). Some more recent SQL +# evolutions such as "INTEGER GENERATED ALWAYS AS expression STORED" are not supported. +# LISTEN/NOTIFY is not supported. +# +# TODO: test YSQL_PASSWORD +# https://docs.yugabyte.com/preview/reference/configuration/yugabyted/ +test-yugabyte: test-pg.el + ${DOCKER} run --rm --name yugabyte \ + --pull=newer \ + --net host \ + -e YSQL_DB=pgeltestdb \ + -e YSQL_USER=pgeltestuser \ + -d docker.io/yugabytedb/yugabyte:latest \ + bin/yugabyted start \ + --ysql_port 5493 \ + --advertise_address 127.0.0.1 \ + --base_dir=/tmp \ + --background=false + sleep 10 + PGURI=postgresql://pgeltestuser@127.0.0.1:5493/pgeltestdb $(MAKE) test + ${DOCKER} stop yugabyte + + +# https://github.com/ApsaraDB/PolarDB-for-PostgreSQL from Alibaba Cloud +# +# Note: primary runs on $POLARDB_PORT, replicas on ${POLARDB_PORT}+1 and ${POLARDB_PORT}+2 +# We don't seem to be able to set POLARDB_DATABASE or equivalent +test-polardb: test-pg.el + ${DOCKER} run --rm --name polardb \ + --pull=newer \ + --publish 127.0.0.1:5998:5998 \ + -e POLARDB_PORT=5998 \ + -e POLARDB_USER=pgeltestuser \ + -e POLARDB_PASSWORD=pgeltest \ + -d docker.io/polardb/polardb_pg_local_instance:15 + sleep 10 + PGURI=postgresql://pgeltestuser:pgeltest@127.0.0.1:5998/postgres $(MAKE) test + ${DOCKER} stop polardb + + # Very limited PostgreSQL support: there is no pg_type table so we can't retrieve information # regarding the OID of builtin types. We have to be careful during the initialization sequence not # to send the query "SET datestyle = 'ISO'", which would fail and cause the network connection to be @@ -1176,7 +1176,7 @@ test-surrealdb: test-pg.el ${DOCKER} run --rm --name surrealdb \ --pull=newer \ --publish 127.0.0.1:8000:8000 \ - -d docker.io/surrealdb/surrealdb:latest start memory \ + -d docker.io/surrealdb/surrealdb:nightly start memory \ --user pgeltestuser --pass pgeltest --log info --allow-experimental sleep 5 PGURI=postgresql://pgeltestuser:pgeltest@127.0.0.1:5433/pgeltestdb $(MAKE) test diff --git a/test/test-pg.el b/test/test-pg.el index 9e1a09b685d..c227cdc479d 100755 --- a/test/test-pg.el +++ b/test/test-pg.el @@ -376,6 +376,7 @@ (funcall test con) (error (message "\033[31;1mTest failed\033[0m: %s" err))) (pg-sync con)) + (message "== Tests finished; producing a report on memory usage") (memory-report) (with-current-buffer "*Memory Report*" (message "%s" (buffer-string)))))) @@ -648,13 +649,15 @@ (should (eql -6 (scalar "SELECT -(6)"))) (should (eql ?Z (scalar "SELECT 'Z'::char"))) (should (eql ?@ (scalar "SELECT '@'::char(1)"))) - (should (eql ?! (scalar "SELECT '!'::bpchar(1)"))) + (unless (member (pgcon-server-variant con) '(cratedb cockroachdb cedardb)) + (should (eql ?! (scalar "SELECT '!'::bpchar(1)")))) (should (string= "Z" (scalar "SELECT 'Z'::varchar"))) (should (string= "É" (scalar "SELECT 'É'::varchar(1)"))) (should (string= "AB" (scalar "SELECT 'AB'::char(2)"))) (should (string= "ÁÔ" (scalar "SELECT 'ÁÔ'::char(2)"))) (should (string= "ÁÔ" (scalar "SELECT 'ÁÔ'::varchar(2)"))) - (should (string= "12" (scalar "SELECT '12'::bpchar(2)"))) + (unless (member (pgcon-server-variant con) '(cratedb cockroachdb cedardb)) + (should (string= "12" (scalar "SELECT '12'::bpchar(2)")))) (should (string= "£Öí" (scalar "SELECT '£Öí'::text"))) (should (string= "Albert" (scalar "SELECT 'Albert'::name"))) (should (string= "AB" (scalar "SELECT 'AB'::varchar(4)"))) @@ -663,7 +666,8 @@ ;; '{' || 'A'::character(10) || '}' only returns a TEXT string of length 3, rather than of ;; length 12. (should (string= "AB " (scalar "SELECT 'AB'::character(5)"))) - (should (string= "AB " (scalar "SELECT 'AB'::bpchar(6)"))) + (unless (member (pgcon-server-variant con) '(cratedb cockroachdb cedardb)) + (should (string= "AB " (scalar "SELECT 'AB'::bpchar(6)")))) ;; Just to note that the space padding is stripped before "semantic comparison", as per ;; https://www.postgresql.org/docs/current/datatype-character.html (should (eql t (scalar "SELECT 'A'::char(1000) = 'A'::char(10)"))) @@ -1457,21 +1461,23 @@ bar$$")))) (should (eql 420 (scalar "SELECT nextval('foo_seq')"))) (should (eql 440 (scalar "SELECT nextval('foo_seq')"))) (pg-exec con "DROP SEQUENCE foo_seq") - (pg-exec con "DROP SEQUENCE IF EXISTS test_seq_nocycle") - (pg-exec con "CREATE SEQUENCE test_seq_nocycle START 1 INCREMENT 1 MAXVALUE 2 NO CYCLE") - (should (eql 1 (scalar "SELECT nextval('test_seq_nocycle')"))) - (should (eql 2 (scalar "SELECT nextval('test_seq_nocycle')"))) - (should (eql 'ok (condition-case nil - (scalar "SELECT nextval('test_seq_nocycle')") - (pg-sequence-limit-exceeded 'ok)))) - (pg-exec con "DROP SEQUENCE test_seq_nocycle") - (pg-exec con "DROP SEQUENCE IF EXISTS test_seq_cycle") - (pg-exec con "CREATE SEQUENCE test_seq_cycle START 1 INCREMENT 1 MAXVALUE 2 CYCLE") - (should (eql 1 (scalar "SELECT nextval('test_seq_cycle')"))) - (should (eql 2 (scalar "SELECT nextval('test_seq_cycle')"))) - ;; should cycle - (should (eql 1 (scalar "SELECT nextval('test_seq_cycle')"))) - (pg-exec con "DROP SEQUENCE test_seq_cycle") + ;; CockroachDB does not implement the CYCLE option on sequences. + (unless (member (pgcon-server-variant con) '(cockroachdb)) + (pg-exec con "DROP SEQUENCE IF EXISTS test_seq_nocycle") + (pg-exec con "CREATE SEQUENCE test_seq_nocycle START 1 INCREMENT 1 MAXVALUE 2 NO CYCLE") + (should (eql 1 (scalar "SELECT nextval('test_seq_nocycle')"))) + (should (eql 2 (scalar "SELECT nextval('test_seq_nocycle')"))) + (should (eql 'ok (condition-case nil + (scalar "SELECT nextval('test_seq_nocycle')") + (pg-sequence-limit-exceeded 'ok)))) + (pg-exec con "DROP SEQUENCE test_seq_nocycle") + (pg-exec con "DROP SEQUENCE IF EXISTS test_seq_cycle") + (pg-exec con "CREATE SEQUENCE test_seq_cycle START 1 INCREMENT 1 MAXVALUE 2 CYCLE") + (should (eql 1 (scalar "SELECT nextval('test_seq_cycle')"))) + (should (eql 2 (scalar "SELECT nextval('test_seq_cycle')"))) + ;; should cycle + (should (eql 1 (scalar "SELECT nextval('test_seq_cycle')"))) + (pg-exec con "DROP SEQUENCE test_seq_cycle")) (pg-exec con "DROP SEQUENCE IF EXISTS test_seq_setval") (pg-exec con "CREATE SEQUENCE test_seq_setval") (should (eql 50 (scalar "SELECT setval('test_seq_setval', 50)"))) @@ -1497,7 +1503,8 @@ bar$$")))) (should (equal (vector) (scalar "SELECT '{}'::bool[]"))) (should (equal (vector) (scalar "SELECT '{}'::float4[]"))) (should (equal (vector) (scalar "SELECT '{}'::float8[]"))) - (should (equal (vector "AB1234" "4321BA") (scalar "SELECT '{\"AB1234\",\"4321BA\"}'::bpchar[]"))) + (unless (member (pgcon-server-variant con) '(cratedb cockroachdb cedardb)) + (should (equal (vector "AB1234" "4321BA") (scalar "SELECT '{\"AB1234\",\"4321BA\"}'::bpchar[]")))) (let ((vec (scalar "SELECT ARRAY[3.14::float]"))) (should (floatp (aref vec 0))) (should (pgtest-approx= 3.14 (aref vec 0)))) @@ -1931,8 +1938,10 @@ bar$$")))) (should (eql 5 d))) (let ((d (scalar "SELECT cosine_distance('[1,2]'::vector, '[0,0]')"))) (should (eql 0.0e+NaN d))) - (let ((d (scalar "SELECT '[1,2,3]'::vector <+> '[4,5,6]'::vector"))) - (should (eql 9 d))) + ;; <+> operator is not supported in CockroachDB + (unless (member (pgcon-server-variant con) '(cockroachdb)) + (let ((d (scalar "SELECT '[1,2,3]'::vector <+> '[4,5,6]'::vector"))) + (should (eql 9 d)))) (let ((d (scalar "SELECT l1_distance('[1,2,3]'::vector, '[4,5,6]'::vector)"))) (should (eql 9 d))) (let ((d (scalar "SELECT '[1,1,1,1]'::vector <=> '[2,2,2,2]'::vector"))) @@ -2565,10 +2574,14 @@ bar$$")))) (pg-data-error 'ok)))) (should (eql 'ok (condition-case nil (scalar "SELECT 'foo' + 'a'::character") - (pg-undefined-function 'ok)))) + (pg-undefined-function 'ok) + ;; CockroachDB reports this as a pg-data-error. + (pg-data-error 'ok)))) (should (eql 'ok (condition-case nil (scalar "SELECT ''::char(0)") - (pg-data-error 'ok)))) + (pg-data-error 'ok) + ;; CockroachDB reports this as a syntax error + (pg-syntax-error 'ok)))) (should (eql 'ok (condition-case nil ;; numerical overflow (scalar "SELECT 2147483649::int4")