Skip to content

Commit 07de18d

Browse files
committed
test(pg smoke test): add tests for cloudsync_pk_encode and for insert/delete triggers and for the content of the metatable
1 parent d658e33 commit 07de18d

1 file changed

Lines changed: 75 additions & 7 deletions

File tree

docker/postgresql/smoke_test.sql

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
-- Enable debug logs
2+
-- SET client_min_messages = debug1; SET log_min_messages = debug1;
3+
SET client_min_messages = warning; SET log_min_messages = warning;
4+
15
\set ON_ERROR_STOP on
26

37
-- Reset extension and install
48
DROP EXTENSION IF EXISTS cloudsync CASCADE;
59
CREATE EXTENSION cloudsync;
610

7-
-- Basic visibility checks
11+
\echo 'Test version visibility'
812
SELECT cloudsync_version() AS version;
913

14+
\echo 'Test uuid generation'
1015
SELECT (length(cloudsync_uuid()) > 0) AS uuid_ok \gset
1116
\if :uuid_ok
1217
\else
13-
\quit 1
18+
DO $$ BEGIN
19+
RAISE EXCEPTION 'smoke test failed: uuid_ok';
20+
END $$;
1421
\endif
1522

1623
-- SELECT (cloudsync_db_version() >= 0) AS dbv_ok \gset
@@ -19,24 +26,85 @@ SELECT (length(cloudsync_uuid()) > 0) AS uuid_ok \gset
1926
-- \quit 1
2027
-- \endif
2128

22-
-- Enable debug logs
23-
SET client_min_messages = debug1; SET log_min_messages = debug1;
24-
25-
-- Init on a simple table should succeed
29+
\echo 'Test init on a simple table'
2630
SELECT cloudsync_cleanup('smoke_tbl');
2731
DROP TABLE IF EXISTS smoke_tbl;
2832
CREATE TABLE smoke_tbl (id TEXT PRIMARY KEY, val TEXT);
2933
SELECT cloudsync_init('smoke_tbl', 'CLS', true);
3034

35+
\echo 'Test insert metadata row creation'
36+
SELECT cloudsync_uuid() AS smoke_id \gset
37+
INSERT INTO smoke_tbl (id, val) VALUES (:'smoke_id', 'hello');
38+
SELECT (COUNT(*) = 1) AS insert_meta_ok
39+
FROM smoke_tbl_cloudsync
40+
WHERE pk = cloudsync_pk_encode(VARIADIC ARRAY[:'smoke_id']::text[])
41+
AND col_name = 'val' \gset
42+
\if :insert_meta_ok
43+
\else
44+
DO $$ BEGIN
45+
RAISE EXCEPTION 'smoke test failed: insert_meta_ok';
46+
END $$;
47+
\endif
48+
\echo 'Test insert metadata fields'
49+
SELECT (db_version > 0 AND seq >= 0) AS insert_meta_fields_ok
50+
FROM smoke_tbl_cloudsync
51+
WHERE pk = cloudsync_pk_encode(VARIADIC ARRAY[:'smoke_id']::text[])
52+
AND col_name = 'val' \gset
53+
\if :insert_meta_fields_ok
54+
\else
55+
DO $$ BEGIN
56+
RAISE EXCEPTION 'smoke test failed: insert_meta_fields_ok';
57+
END $$;
58+
\endif
59+
60+
\echo 'Test delete metadata tombstone'
61+
DELETE FROM smoke_tbl WHERE id = :'smoke_id';
62+
SELECT (COUNT(*) = 1) AS delete_meta_ok
63+
FROM smoke_tbl_cloudsync
64+
WHERE pk = cloudsync_pk_encode(VARIADIC ARRAY[:'smoke_id']::text[])
65+
AND col_name = '__[RIP]__' \gset
66+
\if :delete_meta_ok
67+
\else
68+
DO $$ BEGIN
69+
RAISE EXCEPTION 'smoke test failed: delete_meta_ok';
70+
END $$;
71+
\endif
72+
\echo 'Test delete metadata fields'
73+
SELECT (db_version > 0 AND seq >= 0) AS delete_meta_fields_ok
74+
FROM smoke_tbl_cloudsync
75+
WHERE pk = cloudsync_pk_encode(VARIADIC ARRAY[:'smoke_id']::text[])
76+
AND col_name = '__[RIP]__' \gset
77+
\if :delete_meta_fields_ok
78+
\else
79+
DO $$ BEGIN
80+
RAISE EXCEPTION 'smoke test failed: delete_meta_fields_ok';
81+
END $$;
82+
\endif
83+
84+
\echo 'Test delete removes non-tombstone metadata'
85+
SELECT (COUNT(*) = 0) AS delete_meta_only_ok
86+
FROM smoke_tbl_cloudsync
87+
WHERE pk = cloudsync_pk_encode(VARIADIC ARRAY[:'smoke_id']::text[])
88+
AND col_name != '__[RIP]__' \gset
89+
\if :delete_meta_only_ok
90+
\else
91+
DO $$ BEGIN
92+
RAISE EXCEPTION 'smoke test failed: delete_meta_only_ok';
93+
END $$;
94+
\endif
95+
96+
\echo 'Test site id visibility'
3197
SELECT cloudsync_siteid();
3298

99+
\echo 'Test site id encoding'
33100
SELECT (length(encode(cloudsync_siteid()::bytea, 'hex')) > 0) AS sid_ok \gset
34101
\if :sid_ok
35102
\else
36103
\quit 1
37104
\endif
38105

39-
-- test double init, should be a no-op
106+
\echo 'Test double init no-op'
107+
SELECT cloudsync_init('smoke_tbl', 'CLS', true);
40108
SELECT cloudsync_init('smoke_tbl', 'CLS', true);
41109

42110
SELECT cloudsync_cleanup('smoke_tbl');

0 commit comments

Comments
 (0)