Skip to content

Commit b5aee7d

Browse files
committed
tests: fixes for ptrack
1 parent 96344e4 commit b5aee7d

File tree

1 file changed

+92
-5
lines changed

1 file changed

+92
-5
lines changed

tests/ptrack.py

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, idx_ptrack
44
from datetime import datetime, timedelta
55
import subprocess
6-
from testgres import QueryException
6+
from testgres import QueryException, StartNodeException
77
import shutil
88
import sys
9-
import time
9+
from time import sleep
1010
from threading import Thread
1111

1212

@@ -3848,7 +3848,7 @@ def test_ptrack_zero_changes(self):
38483848
self.del_test_dir(module_name, fname)
38493849

38503850
# @unittest.skip("skip")
3851-
# @unittest.expectedFailure
3851+
@unittest.expectedFailure
38523852
def test_ptrack_pg_resetxlog(self):
38533853
fname = self.id().split('.')[3]
38543854
node = self.make_simple_node(
@@ -4016,28 +4016,115 @@ def test_corrupt_ptrack_map(self):
40164016

40174017
node.stop(['-m', 'immediate', '-D', node.data_dir])
40184018

4019+
ptrack_map = os.path.join(node.data_dir, 'global', 'ptrack.map')
4020+
ptrack_map_mmap = os.path.join(node.data_dir, 'global', 'ptrack.map.mmap')
4021+
40194022
# Let`s do index corruption. ptrack.map, ptrack.map.mmap
4020-
with open(os.path.join(node.data_dir, 'global', 'ptrack.map'), "rb+", 0) as f:
4023+
with open(ptrack_map, "rb+", 0) as f:
40214024
f.seek(42)
40224025
f.write(b"blablahblahs")
40234026
f.flush()
40244027
f.close
40254028

4026-
with open(os.path.join(node.data_dir, 'global', 'ptrack.map.mmap'), "rb+", 0) as f:
4029+
with open(ptrack_map_mmap, "rb+", 0) as f:
40274030
f.seek(42)
40284031
f.write(b"blablahblahs")
40294032
f.flush()
40304033
f.close
40314034

40324035
# os.remove(os.path.join(node.logs_dir, node.pg_log_name))
40334036

4037+
try:
4038+
node.slow_start()
4039+
# we should die here because exception is what we expect to happen
4040+
self.assertEqual(
4041+
1, 0,
4042+
"Expecting Error because ptrack.map is corrupted"
4043+
"\n Output: {0} \n CMD: {1}".format(
4044+
repr(self.output), self.cmd))
4045+
except StartNodeException as e:
4046+
self.assertIn(
4047+
'Cannot start node',
4048+
e.message,
4049+
'\n Unexpected Error Message: {0}\n'
4050+
' CMD: {1}'.format(repr(e.message), self.cmd))
4051+
4052+
log_file = os.path.join(node.logs_dir, 'postgresql.log')
4053+
with open(log_file, 'r') as f:
4054+
log_content = f.read()
4055+
4056+
self.assertIn(
4057+
'FATAL: incorrect checksum of file "{0}"'.format(ptrack_map),
4058+
log_content)
4059+
4060+
self.set_auto_conf(node, {'ptrack_map_size': '0'})
4061+
4062+
node.slow_start()
4063+
4064+
try:
4065+
self.backup_node(
4066+
backup_dir, 'node', node,
4067+
backup_type='ptrack', options=['--stream'])
4068+
# we should die here because exception is what we expect to happen
4069+
self.assertEqual(
4070+
1, 0,
4071+
"Expecting Error because instance ptrack is disabled"
4072+
"\n Output: {0} \n CMD: {1}".format(
4073+
repr(self.output), self.cmd))
4074+
except ProbackupException as e:
4075+
self.assertIn(
4076+
'ERROR: Ptrack is disabled',
4077+
e.message,
4078+
'\n Unexpected Error Message: {0}\n'
4079+
' CMD: {1}'.format(repr(e.message), self.cmd))
4080+
4081+
node.safe_psql(
4082+
'postgres',
4083+
"update t_heap set id = nextval('t_seq'), text = md5(text), "
4084+
"tsvector = md5(repeat(tsvector::text, 10))::tsvector")
4085+
4086+
node.stop(['-m', 'immediate', '-D', node.data_dir])
4087+
4088+
self.set_auto_conf(node, {'ptrack_map_size': '32'})
4089+
40344090
node.slow_start()
40354091

4092+
sleep(1)
4093+
4094+
try:
4095+
self.backup_node(
4096+
backup_dir, 'node', node,
4097+
backup_type='ptrack', options=['--stream'])
4098+
# we should die here because exception is what we expect to happen
4099+
self.assertEqual(
4100+
1, 0,
4101+
"Expecting Error because ptrack map is from future"
4102+
"\n Output: {0} \n CMD: {1}".format(
4103+
repr(self.output), self.cmd))
4104+
except ProbackupException as e:
4105+
self.assertIn(
4106+
'ERROR: LSN from ptrack_control',
4107+
e.message,
4108+
'\n Unexpected Error Message: {0}\n'
4109+
' CMD: {1}'.format(repr(e.message), self.cmd))
4110+
4111+
sleep(1)
4112+
4113+
self.backup_node(
4114+
backup_dir, 'node', node,
4115+
backup_type='delta', options=['--stream'])
4116+
4117+
node.safe_psql(
4118+
'postgres',
4119+
"update t_heap set id = nextval('t_seq'), text = md5(text), "
4120+
"tsvector = md5(repeat(tsvector::text, 10))::tsvector")
4121+
40364122
self.backup_node(
40374123
backup_dir, 'node', node,
40384124
backup_type='ptrack', options=['--stream'])
40394125

40404126
pgdata = self.pgdata_content(node.data_dir)
4127+
40414128
node.cleanup()
40424129

40434130
self.restore_node(backup_dir, 'node', node)

0 commit comments

Comments
 (0)