Skip to content

Commit 29a9efb

Browse files
committed
[PBCKP-325] refix test_issue_231
to make two backups in one second we have to fail them. Therefore we have to fetch backup_id from log in exception's message. Retry for 20 seconds to have a chance to start in one second. If we couldn't, lets skip the test.
1 parent bef73b8 commit 29a9efb

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tests/backup_test.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
import os
3+
import re
34
from time import sleep, time
45
from .helpers.ptrack_helpers import base36enc, ProbackupTest, ProbackupException
56
import shutil
@@ -2780,18 +2781,33 @@ def test_issue_231(self):
27802781
"""
27812782
backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
27822783
node = self.make_simple_node(
2783-
base_dir=os.path.join(self.module_name, self.fname, 'node'),
2784-
set_replication=True,
2785-
initdb_params=['--data-checksums'])
2784+
base_dir=os.path.join(self.module_name, self.fname, 'node'))
27862785

27872786
self.init_pb(backup_dir)
27882787
self.add_instance(backup_dir, 'node', node)
2789-
node.slow_start()
27902788

27912789
datadir = os.path.join(node.data_dir, '123')
27922790

2793-
pb1 = self.backup_node(backup_dir, 'node', node, data_dir='{0}'.format(datadir))
2794-
pb2 = self.backup_node(backup_dir, 'node', node, options=['--stream'])
2791+
t0 = time()
2792+
while True:
2793+
with self.assertRaises(ProbackupException) as ctx:
2794+
self.backup_node(backup_dir, 'node', node)
2795+
pb1 = re.search(r' backup ID: ([^\s,]+),', ctx.exception.message).groups()[0]
2796+
2797+
t = time()
2798+
if int(pb1, 36) == int(t) and t % 1 < 0.5:
2799+
# ok, we have a chance to start next backup in same second
2800+
break
2801+
elif t - t0 > 20:
2802+
# Oops, we are waiting for too long. Looks like this runner
2803+
# is too slow. Lets skip the test.
2804+
self.skipTest("runner is too slow")
2805+
# sleep to the second's end so backup will not sleep for a second.
2806+
sleep(1 - t % 1)
2807+
2808+
with self.assertRaises(ProbackupException) as ctx:
2809+
self.backup_node(backup_dir, 'node', node)
2810+
pb2 = re.search(r' backup ID: ([^\s,]+),', ctx.exception.message).groups()[0]
27952811

27962812
self.assertNotEqual(pb1, pb2)
27972813

0 commit comments

Comments
 (0)