Skip to content

Commit 17c1b31

Browse files
committed
tests: archive compression
1 parent a43c951 commit 17c1b31

File tree

3 files changed

+105
-11
lines changed

3 files changed

+105
-11
lines changed

tests/Readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
Note: For now there are tests only for Linix
55
```
66

7+
78
```
9+
Check physical correctness of restored instances.
10+
Apply this patch to disable HINT BITS: https://gist.github.com/gsmol/2bb34fd3ba31984369a72cc1c27a36b6
11+
export PG_PROBACKUP_PARANOIA=ON
12+
13+
Check archive compression:
14+
export ARCHIVE_COMPRESSION=ON
15+
816
export PG_CONFIG=/path/to/pg_config
9-
export PGPRO_PARANOIA_MODE=ON/OFF
17+
pip install testgres=0.4.0
1018
python -m unittest [-v] tests
1119
```

tests/archive.py

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def test_pgpro434_1(self):
2626
self.init_pb(backup_dir)
2727
self.add_instance(backup_dir, 'node', node)
2828
self.set_archiving(backup_dir, 'node', node)
29-
# force more frequent wal switch
30-
node.append_conf('postgresql.auto.conf', 'archive_timeout = 30')
3129
node.start()
3230

3331
node.safe_psql(
@@ -206,7 +204,7 @@ def test_arhive_push_file_exists(self):
206204
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
207205
set_replication=True,
208206
initdb_params=['--data-checksums'],
209-
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s', 'archive_timeout': '1'}
207+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s'}
210208
)
211209
self.init_pb(backup_dir)
212210
self.add_instance(backup_dir, 'node', node)
@@ -257,7 +255,6 @@ def test_replica_archive(self):
257255
self.init_pb(backup_dir)
258256
# ADD INSTANCE 'MASTER'
259257
self.add_instance(backup_dir, 'master', master)
260-
# force more frequent wal switch
261258
master.start()
262259

263260
replica = self.make_simple_node(base_dir="{0}/{1}/replica".format(module_name, fname))
@@ -386,6 +383,93 @@ def test_master_and_replica_concurrent_archiving(self):
386383
# @unittest.expectedFailure
387384
@unittest.skip("skip")
388385
def test_archive_compress(self):
386+
"""Test compression"""
387+
fname = self.id().split('.')[3]
388+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
389+
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
390+
set_replication=True,
391+
initdb_params=['--data-checksums'],
392+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s'}
393+
)
394+
self.init_pb(backup_dir)
395+
self.add_instance(backup_dir, 'node', node)
396+
self.set_archiving(backup_dir, 'node', node)
397+
node.start()
398+
399+
self.backup_node(backup_dir, 'node', node)
400+
401+
node.safe_psql(
402+
"postgres",
403+
"create table t_heap as select 1 as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,10000) i")
404+
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
405+
406+
self.backup_node(backup_dir, 'node', node, backup_type='page')
407+
408+
node.cleanup()
409+
self.restore_node(backup_dir, 'node', node)
410+
411+
node.start()
412+
413+
self.assertEqual(result, node.safe_psql("postgres", "SELECT * FROM t_heap"),
414+
'data after restore not equal to original data')
415+
416+
417+
self.backup_node(backup_dir, 'node', node)
418+
419+
node.safe_psql(
420+
"postgres",
421+
"insert into t_heap select i as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(10000,20000) i")
422+
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
423+
424+
self.backup_node(backup_dir, 'node', node, backup_type='page')
425+
426+
node.cleanup()
427+
self.restore_node(backup_dir, 'node', node)
428+
429+
node.start()
430+
431+
self.assertEqual(result, node.safe_psql("postgres", "SELECT * FROM t_heap"),
432+
'data after restore not equal to original data')
433+
434+
# Clean after yourself
435+
# self.del_test_dir(module_name, fname)
436+
437+
# @unittest.expectedFailure
438+
@unittest.skip("skip")
439+
def test_archive_pg_receivexlog(self):
440+
"""Description in jira issue PGPRO-434"""
441+
fname = self.id().split('.')[3]
442+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
443+
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
444+
set_replication=True,
445+
initdb_params=['--data-checksums'],
446+
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', 'checkpoint_timeout': '30s'}
447+
)
448+
self.init_pb(backup_dir)
449+
self.add_instance(backup_dir, 'node', node)
450+
self.set_archiving(backup_dir, 'node', node)
451+
node.start()
452+
453+
node.safe_psql(
454+
"postgres",
455+
"create table t_heap as select 1 as id, md5(i::text) as text, md5(repeat(i::text,10))::tsvector as tsvector from generate_series(0,100) i")
456+
457+
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
458+
self.backup_node(backup_dir, 'node', node)
459+
460+
node.cleanup()
461+
462+
self.restore_node(backup_dir, 'node', node, backup_type='page')
463+
node.start()
464+
465+
self.assertEqual(result, node.safe_psql("postgres", "SELECT * FROM t_heap"),
466+
'data after restore not equal to original data')
467+
# Clean after yourself
468+
# self.del_test_dir(module_name, fname)
469+
470+
# @unittest.expectedFailure
471+
@unittest.skip("skip")
472+
def test_archive_pg_receivexlog_compression_pg_10(self):
389473
"""Description in jira issue PGPRO-434"""
390474
fname = self.id().split('.')[3]
391475
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
@@ -397,8 +481,6 @@ def test_archive_compress(self):
397481
self.init_pb(backup_dir)
398482
self.add_instance(backup_dir, 'node', node)
399483
self.set_archiving(backup_dir, 'node', node)
400-
# force more frequent wal switch
401-
node.append_conf('postgresql.auto.conf', 'archive_timeout = 30')
402484
node.start()
403485

404486
node.safe_psql(

tests/helpers/ptrack_helpers.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ def __init__(self, *args, **kwargs):
125125
self.test_env["LC_TIME"] = "C"
126126

127127
self.paranoia = False
128-
if 'PGPRO_PARANOIA_MODE' in self.test_env:
129-
if self.test_env['PGPRO_PARANOIA_MODE'] == 'ON':
128+
if 'PG_PROBACKUP_PARANOIA' in self.test_env:
129+
if self.test_env['PG_PROBACKUP_PARANOIA'] == 'ON':
130130
self.paranoia = True
131131

132+
if 'ARCHIVE_COMPRESSION' in self.test_env:
133+
if self.test_env['ARCHIVE_COMPRESSION'] == 'ON':
134+
self.archive_compress = True
135+
132136
self.helpers_path = os.path.dirname(os.path.realpath(__file__))
133137
self.dir_path = os.path.abspath(os.path.join(self.helpers_path, os.pardir))
134138
self.tmp_path = os.path.abspath(os.path.join(self.dir_path, 'tmp_dirs'))
@@ -559,7 +563,7 @@ def get_recovery_conf(self, node):
559563
out_dict[key.strip()] = value.strip(" '").replace("'\n", "")
560564
return out_dict
561565

562-
def set_archiving(self, backup_dir, instance, node, replica=False, compress=False):
566+
def set_archiving(self, backup_dir, instance, node, replica=False):
563567

564568
if replica:
565569
archive_mode = 'always'
@@ -576,7 +580,7 @@ def set_archiving(self, backup_dir, instance, node, replica=False, compress=Fals
576580
"archive_mode = {0}".format(archive_mode)
577581
)
578582
if os.name == 'posix':
579-
if compress:
583+
if self.archive_compress:
580584
node.append_conf(
581585
"postgresql.auto.conf",
582586
"archive_command = '{0} archive-push -B {1} --instance={2} --compress --wal-file-path %p --wal-file-name %f'".format(

0 commit comments

Comments
 (0)