Skip to content

Commit ae111a1

Browse files
committed
test(postgresql): move the smoke test to the test/postgresql dir
Also split the smoke test into different test files, all these test files are called by smoke_test.sql
1 parent c8a9153 commit ae111a1

File tree

6 files changed

+736
-64
lines changed

6 files changed

+736
-64
lines changed
Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
-- usage:
2-
-- - normal: `psql postgresql://postgres:postgres@localhost:5432/cloudsync_test -f docker/postgresql/smoke_test.sql`
3-
-- - debug: `psql -v DEBUG=1 postgresql://postgres:postgres@localhost:5432/cloudsync_test -f docker/postgresql/smoke_test.sql`
1+
\connect postgres
2+
\ir helper_psql_conn_setup.sql
43

54
DROP DATABASE IF EXISTS cloudsync_test_1;
65
CREATE DATABASE cloudsync_test_1;
7-
\connect cloudsync_test_1
86

9-
\set ON_ERROR_STOP on
10-
\set fail 0
11-
\if :{?DEBUG}
12-
SET client_min_messages = debug1; SET log_min_messages = debug1; SET log_error_verbosity = verbose;
13-
\set QUIET 0
14-
\pset tuples_only off
15-
\pset format aligned
16-
\echo '[DEBUG] verbose output enabled'
17-
\else
18-
\set QUIET 1
19-
\pset tuples_only on
20-
\pset format unaligned
21-
SET client_min_messages = warning; SET log_min_messages = warning;
22-
\endif
7+
\connect cloudsync_test_1
8+
\ir helper_psql_conn_setup.sql
239

2410
-- Reset extension and install
2511
-- DROP EXTENSION IF EXISTS cloudsync CASCADE;
@@ -38,12 +24,6 @@ SELECT (length(cloudsync_uuid()) > 0) AS uuid_ok \gset
3824
SELECT (:fail::int + 1) AS fail \gset
3925
\endif
4026

41-
-- SELECT (cloudsync_db_version() >= 0) AS dbv_ok \gset
42-
-- \if :dbv_ok
43-
-- \else
44-
-- \quit 1
45-
-- \endif
46-
4727
-- 'Test init on a simple table'
4828
SELECT cloudsync_cleanup('smoke_tbl') AS _cleanup_ok \gset
4929
SELECT (cloudsync_is_sync('smoke_tbl') = false) AS init_cleanup_ok \gset
@@ -290,50 +270,16 @@ SELECT cloudsync_init('smoke_tbl', 'CLS', true) AS _init_site_id2 \gset
290270
SELECT cloudsync_init('smoke_tbl', 'CLS', true) AS _init_site_id3 \gset
291271
\echo '[PASS] Test double init no-op'
292272

293-
-- 'Test payload roundtrip to another database'
273+
-- 'Test payload encode signature'
294274
SELECT md5(COALESCE(string_agg(id || ':' || COALESCE(val, ''), ',' ORDER BY id), '')) AS smoke_hash
295275
FROM smoke_tbl \gset
296276
SELECT encode(cloudsync_payload_encode(tbl, pk, col_name, col_value, col_version, db_version, site_id, cl, seq), 'hex') AS payload_hex
297277
FROM cloudsync_changes
298278
WHERE site_id = cloudsync_siteid() \gset
299-
DROP DATABASE IF EXISTS cloudsync_test_2;
300-
CREATE DATABASE cloudsync_test_2;
301-
\connect cloudsync_test_2
302-
\if :{?DEBUG}
303-
SET client_min_messages = debug1; SET log_min_messages = debug1; SET log_error_verbosity = verbose;
304-
\set QUIET 0
305-
\pset tuples_only off
306-
\pset format aligned
279+
SELECT (length(:'payload_hex') > 0 AND substring(:'payload_hex' from 1 for 8) = '434c5359') AS payload_sig_ok \gset
280+
\if :payload_sig_ok
281+
\echo '[PASS] Test payload encode signature'
307282
\else
308-
SET client_min_messages = warning; SET log_min_messages = warning;
309-
\set QUIET 1
310-
\pset tuples_only on
311-
\pset format unaligned
312-
\endif
313-
CREATE EXTENSION IF NOT EXISTS cloudsync;
314-
DROP TABLE IF EXISTS smoke_tbl;
315-
CREATE TABLE smoke_tbl (id TEXT PRIMARY KEY, val TEXT);
316-
SELECT cloudsync_init('smoke_tbl', 'CLS', true) AS _init_site_id_b \gset
317-
SELECT cloudsync_payload_apply(decode(:'payload_hex', 'hex')) AS _apply_ok \gset
318-
SELECT md5(COALESCE(string_agg(id || ':' || COALESCE(val, ''), ',' ORDER BY id), '')) AS smoke_hash_b
319-
FROM smoke_tbl \gset
320-
SELECT (:'smoke_hash' = :'smoke_hash_b') AS payload_roundtrip_ok \gset
321-
\if :payload_roundtrip_ok
322-
\echo '[PASS] Test payload roundtrip to another database'
323-
\else
324-
\echo '[FAIL] Test payload roundtrip to another database'
283+
\echo '[FAIL] Test payload encode signature'
325284
SELECT (:fail::int + 1) AS fail \gset
326-
\endif
327-
328-
-- 'Test summary'
329-
\echo '\nTest summary:'
330-
\echo - Failures: :fail
331-
SELECT (:fail::int > 0) AS fail_any \gset
332-
\if :fail_any
333-
\echo smoke test failed: :fail test(s) failed
334-
DO $$ BEGIN
335-
RAISE EXCEPTION 'smoke test failed';
336-
END $$;
337-
\else
338-
\echo - Status: OK
339-
\endif
285+
\endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
DROP DATABASE IF EXISTS cloudsync_test_2;
2+
CREATE DATABASE cloudsync_test_2;
3+
\connect cloudsync_test_2
4+
\ir helper_psql_conn_setup.sql
5+
CREATE EXTENSION IF NOT EXISTS cloudsync;
6+
DROP TABLE IF EXISTS smoke_tbl;
7+
CREATE TABLE smoke_tbl (id TEXT PRIMARY KEY, val TEXT);
8+
SELECT cloudsync_init('smoke_tbl', 'CLS', true) AS _init_site_id_b \gset
9+
SELECT cloudsync_payload_apply(decode(:'payload_hex', 'hex')) AS _apply_ok \gset
10+
SELECT md5(COALESCE(string_agg(id || ':' || COALESCE(val, ''), ',' ORDER BY id), '')) AS smoke_hash_b
11+
FROM smoke_tbl \gset
12+
SELECT (:'smoke_hash' = :'smoke_hash_b') AS payload_roundtrip_ok \gset
13+
\if :payload_roundtrip_ok
14+
\echo '[PASS] Test payload roundtrip to another database'
15+
\else
16+
\echo '[FAIL] Test payload roundtrip to another database'
17+
SELECT (:fail::int + 1) AS fail \gset
18+
\endif

0 commit comments

Comments
 (0)