Skip to content

Commit 5975865

Browse files
committed
PG-1867 Improve archiving test and fix race condition
There was a race condition in the WAL archiving tests where if the end-of-recovery checkpoint had completed the tests for the WAL contents were non-sensical and racy. Solve this by explicilty promoting the server first after we have looked at the WAL contents. Additionally improve the tests by actually making sure the replica starts in a good state where all WAL is encrypted.
1 parent 80e0bb0 commit 5975865

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

contrib/pg_tde/t/wal_archiving.pl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@
3737
"SELECT pg_tde_set_server_key_using_global_key_provider('server-key', 'keyring');"
3838
);
3939

40+
# This is a quite ugly dance to make sure the replica starts the state where
41+
# WAL encryption is enabled and also generate both some plaintext and some
42+
# encrypted WAL.
43+
#
44+
# We do this by taking the base backup while encryption is enabled. Then we
45+
# turn it off again to generate some plaintext WAL and turn it back on again
46+
# then generate some encrypted WAL.
47+
4048
$primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = on");
4149

50+
$primary->restart;
51+
4252
$primary->backup('backup', backup_options => [ '-X', 'none' ]);
4353

54+
$primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = off");
55+
56+
$primary->restart;
57+
58+
$primary->append_conf('postgresql.conf', "pg_tde.wal_encrypt = on");
59+
4460
$primary->safe_psql('postgres',
4561
"CREATE TABLE t1 AS SELECT 'foobar_plain' AS x");
4662

@@ -79,20 +95,22 @@
7995
"restore_command = 'pg_tde_restore_encrypt %f %p \"cp $archive_dir/%%f %%p\"'"
8096
);
8197
$replica->append_conf('postgresql.conf', "recovery_target_action = promote");
82-
$replica->set_recovery_mode;
98+
$replica->set_standby_mode;
8399
$replica->start;
84100

85101
$data_dir = $replica->data_dir;
86102

87-
like(
103+
unlike(
88104
`strings $data_dir/pg_wal/0000000100000000000000??`,
89105
qr/foobar_plain/,
90-
'should find foobar_plain in WAL since we use the same key file');
106+
'should not find foobar_plain in WAL since it is encrypted');
91107
unlike(
92108
`strings $data_dir/pg_wal/0000000100000000000000??`,
93109
qr/foobar_enc/,
94110
'should not find foobar_enc in WAL since it is encrypted');
95111

112+
$replica->promote;
113+
96114
my $result = $replica->safe_psql('postgres',
97115
'SELECT * FROM t1 UNION ALL SELECT * FROM t2');
98116

0 commit comments

Comments
 (0)