Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2050832

Browse files
author
Amit Kapila
committed
Fix the unstable output of tests added by commit 8fccf75.
The test cases added by that commit were trying to test the exact number of times a particular transaction has spilled. However, that number can vary if any background transaction (say by autovacuum) happens in parallel to the main transaction. So let's not try to verify the exact count. Author: Amit Kapila Reviewed-by: Sawada Masahiko Discussion: https://postgr.es/m/CA+fd4k5_pPAYRTDrO2PbtTOe0eHQpBvuqmCr8ic39uTNmR49Eg@mail.gmail.com
1 parent 323ae00 commit 2050832

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

contrib/test_decoding/expected/stats.out

+11-9
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,25 @@ $$ LANGUAGE plpgsql;
4242
BEGIN;
4343
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
4444
COMMIT;
45-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL,NULL);
45+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
4646
count
4747
-------
48-
5006
48+
5002
4949
(1 row)
5050

51-
-- check stats, wait for stats collector to update.
51+
-- Check stats, wait for the stats collector to update. We can't test the
52+
-- exact stats count as that can vary if any background transaction (say by
53+
-- autovacuum) happens in parallel to the main transaction.
5254
SELECT wait_for_decode_stats(false);
5355
wait_for_decode_stats
5456
-----------------------
5557

5658
(1 row)
5759

58-
SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
60+
SELECT name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
5961
name | spill_txns | spill_count
6062
-----------------+------------+-------------
61-
regression_slot | 1 | 12
63+
regression_slot | t | t
6264
(1 row)
6365

6466
-- reset the slot stats, and wait for stats collector to reset
@@ -81,10 +83,10 @@ SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
8183
(1 row)
8284

8385
-- decode and check stats again.
84-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL,NULL);
86+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
8587
count
8688
-------
87-
5006
89+
5002
8890
(1 row)
8991

9092
SELECT wait_for_decode_stats(false);
@@ -93,10 +95,10 @@ SELECT wait_for_decode_stats(false);
9395

9496
(1 row)
9597

96-
SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
98+
SELECT name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
9799
name | spill_txns | spill_count
98100
-----------------+------------+-------------
99-
regression_slot | 1 | 12
101+
regression_slot | t | t
100102
(1 row)
101103

102104
DROP FUNCTION wait_for_decode_stats(bool);

contrib/test_decoding/sql/stats.sql

+7-5
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ $$ LANGUAGE plpgsql;
4141
BEGIN;
4242
INSERT INTO stats_test SELECT 'serialize-topbig--1:'||g.i FROM generate_series(1, 5000) g(i);
4343
COMMIT;
44-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL,NULL);
44+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
4545

46-
-- check stats, wait for stats collector to update.
46+
-- Check stats, wait for the stats collector to update. We can't test the
47+
-- exact stats count as that can vary if any background transaction (say by
48+
-- autovacuum) happens in parallel to the main transaction.
4749
SELECT wait_for_decode_stats(false);
48-
SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
50+
SELECT name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
4951

5052
-- reset the slot stats, and wait for stats collector to reset
5153
SELECT pg_stat_reset_replication_slot('regression_slot');
5254
SELECT wait_for_decode_stats(true);
5355
SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
5456

5557
-- decode and check stats again.
56-
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL,NULL);
58+
SELECT count(*) FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'skip-empty-xacts', '1');
5759
SELECT wait_for_decode_stats(false);
58-
SELECT name, spill_txns, spill_count FROM pg_stat_replication_slots;
60+
SELECT name, spill_txns > 0 AS spill_txns, spill_count > 0 AS spill_count FROM pg_stat_replication_slots;
5961

6062
DROP FUNCTION wait_for_decode_stats(bool);
6163
DROP TABLE stats_test;

0 commit comments

Comments
 (0)