Skip to content

Commit 62ff7c7

Browse files
committed
test(postgres): tolerate expected errors in corrupted-payload tests
Tests 3 and 4 in 41_corrupted_payload.sql and the post-alter apply in 46_schema_hash_mismatch.sql intentionally feed garbage to cloudsync_payload_apply at the top level and verify the table state is unchanged. With ON_ERROR_STOP now enabled in CI, these expected errors aborted the run. Wrap each intentional-error call in \set ON_ERROR_STOP off / on so psql keeps going while the integrity assertions below still execute. Drop the psql:.*ERROR arm of the workflow grep — ON_ERROR_STOP and the [FAIL] grep already cover unexpected failures, and the dropped arm would false-positive on the now-tolerated stderr lines.
1 parent 4366ace commit 62ff7c7

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ jobs:
277277
docker exec cloudsync-postgres mkdir -p /tmp/cloudsync/test
278278
docker cp test/postgresql cloudsync-postgres:/tmp/cloudsync/test/postgresql
279279
docker exec cloudsync-postgres psql -v ON_ERROR_STOP=on -U postgres -d postgres -f /tmp/cloudsync/test/postgresql/full_test.sql 2>&1 | tee /tmp/pgtest.log
280-
if grep -Eq '^(\[FAIL\]|psql:.*ERROR)' /tmp/pgtest.log; then
280+
if grep -q '^\[FAIL\]' /tmp/pgtest.log; then
281281
echo "::error::PostgreSQL test failures detected"
282282
exit 1
283283
fi

test/postgresql/41_corrupted_payload.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ SELECT (:fail::int + 1) AS fail \gset
7676
-- Test 3: Truncated payload (first 10 bytes of valid payload)
7777
-- Build truncated hex at top level using psql variable interpolation
7878
SELECT substr(:'valid_payload_hex', 1, 20) AS truncated_hex \gset
79+
-- Expected: error on truncated payload — locally disable ON_ERROR_STOP
80+
\set ON_ERROR_STOP off
7981
SELECT cloudsync_payload_apply(decode(:'truncated_hex', 'hex')) AS _apply_truncated \gset
80-
-- If the above errors, psql continues (ON_ERROR_STOP is off)
82+
\set ON_ERROR_STOP on
8183

8284
SELECT COUNT(*) AS count_after_truncated FROM test_tbl \gset
8385
SELECT (:count_after_truncated::int = :initial_count::int) AS truncated_ok \gset
@@ -95,8 +97,10 @@ SELECT
9597
|| lpad(to_hex(get_byte(decode(substr(:'valid_payload_hex', length(:'valid_payload_hex') / 2, 2), 'hex'), 0) # 255), 2, '0')
9698
|| substr(:'valid_payload_hex', length(:'valid_payload_hex') / 2 + 2)
9799
AS corrupted_hex \gset
100+
-- Expected: error on corrupted payload — locally disable ON_ERROR_STOP
101+
\set ON_ERROR_STOP off
98102
SELECT cloudsync_payload_apply(decode(:'corrupted_hex', 'hex')) AS _apply_corrupted \gset
99-
-- If the above errors, psql continues (ON_ERROR_STOP is off)
103+
\set ON_ERROR_STOP on
100104

101105
SELECT COUNT(*) AS count_after_flipped FROM test_tbl \gset
102106
SELECT (:count_after_flipped::int = :initial_count::int) AS flipped_ok \gset

test/postgresql/46_schema_hash_mismatch.sql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ WHERE site_id = cloudsync_siteid() \gset
6161
SELECT cloudsync_init('test_tbl', 'CLS', 1) AS _reinit_dst \gset
6262

6363
-- The apply may error due to schema mismatch, or succeed silently.
64-
-- Either outcome is acceptable — the key is no corruption.
65-
\set apply_ok true
64+
-- Either outcome is acceptable — the key is no corruption (verified below).
65+
\set ON_ERROR_STOP off
6666
SELECT cloudsync_payload_apply(decode(:'payload_post_alter', 'hex')) AS _apply_mismatch \gset
67-
-- If the above errors, psql continues (ON_ERROR_STOP is off) and apply_ok stays true.
68-
-- The test just verifies integrity below.
67+
\set ON_ERROR_STOP on
6968

7069
-- Verify database is in a consistent state (not corrupted)
7170
SELECT COUNT(*) AS final_count FROM test_tbl \gset

0 commit comments

Comments
 (0)