Skip to content

Commit bf2830b

Browse files
author
Artur Zakirov
committed
Fix tests for retention policy. Compare WAL segments without timelineid
1 parent 5aded20 commit bf2830b

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

delete.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,10 @@ delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, bool delete_all)
349349
* they were originally written, in case this worries you.
350350
*/
351351
if (IsXLogFileName(arcde->d_name) ||
352-
IsPartialXLogFileName(arcde->d_name) ||
353-
IsBackupHistoryFileName(arcde->d_name))
352+
IsPartialXLogFileName(arcde->d_name))
354353
{
355354
if (XLogRecPtrIsInvalid(oldest_lsn) ||
356-
strncmp(arcde->d_name, oldestSegmentNeeded,
357-
XLOG_FNAME_LEN) < 0)
355+
strcmp(arcde->d_name + 8, oldestSegmentNeeded + 8) < 0)
358356
{
359357
/*
360358
* Use the original file name again now, including any

tests/option_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,21 @@ def test_options_4(self):
8989
self.clean_pb(node)
9090
self.assertEqual(self.init_pb(node), six.b(""))
9191

92-
# TODO: keep data generations
92+
# Command line parameters should override file values
93+
self.init_pb(node)
94+
with open(path.join(self.backup_dir(node), "pg_probackup.conf"), "a") as conf:
95+
conf.write("REDUNDANCY=1\n")
96+
97+
self.assertEqual(
98+
self.retention_show(node, ["--redundancy", "2"]),
99+
six.b("# retention policy\nREDUNDANCY=2\n")
100+
)
101+
102+
# User cannot send --system-identifier parameter via command line
103+
self.assertEqual(
104+
self.backup_pb(node, options=["--system-identifier", "123"]),
105+
six.b("ERROR: option system-identifier cannot be specified in command line\n")
106+
)
93107

94108
# invalid value in pg_probackup.conf
95109
with open(path.join(self.backup_dir(node), "pg_probackup.conf"), "a") as conf:

tests/pb_lib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ def retention_purge_pb(self, node, options=[]):
195195

196196
return self.run_pb(options + cmd_list)
197197

198+
def retention_show(self, node, options=[]):
199+
cmd_list = [
200+
"-B", self.backup_dir(node),
201+
"retention", "show",
202+
]
203+
204+
return self.run_pb(options + cmd_list)
205+
198206
def get_control_data(self, node):
199207
pg_controldata = node.get_bin_path("pg_controldata")
200208
out_data = {}

tests/retention_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import os
33
from datetime import datetime, timedelta
4-
from os import path
4+
from os import path, listdir
55
from .pb_lib import ProbackupTest
66
from testgres import stop_all
77

@@ -35,9 +35,23 @@ def test_retention_redundancy_1(self):
3535
self.assertEqual(len(self.show_pb(node)), 4)
3636

3737
# Purge backups
38-
self.retention_purge_pb(node)
38+
log = self.retention_purge_pb(node)
3939
self.assertEqual(len(self.show_pb(node)), 2)
4040

41+
# Check that WAL segments were deleted
42+
min_wal = None
43+
max_wal = None
44+
for line in log.splitlines():
45+
if line.startswith(b"INFO: removed min WAL segment"):
46+
min_wal = line[31:-1]
47+
elif line.startswith(b"INFO: removed max WAL segment"):
48+
max_wal = line[31:-1]
49+
for wal_name in listdir(path.join(self.backup_dir(node), "wal")):
50+
if not wal_name.endswith(".backup"):
51+
wal_name_b = wal_name.encode('ascii')
52+
self.assertEqual(wal_name_b[8:] > min_wal[8:], True)
53+
self.assertEqual(wal_name_b[8:] > max_wal[8:], True)
54+
4155
node.stop()
4256

4357
def test_retention_window_2(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy