Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8b480e

Browse files
committed
try to fix test_archive_get_batching_sanity
1 parentf5c0980 commitf8b480e

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

‎tests/archive_test.py‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importgzip
44
importunittest
55
from .helpers.ptrack_helpersimportProbackupTest,ProbackupException,GdbException
6+
from .helpers.ptrack_helpersimporttail_file
67
fromdatetimeimportdatetime,timedelta
78
importsubprocess
89
fromsysimportexit
@@ -2204,7 +2205,7 @@ def test_archive_get_prefetch_corruption(self):
22042205

22052206
self.backup_node(backup_dir,'node',node,options=['--stream'])
22062207

2207-
node.pgbench_init(scale=50)
2208+
node.pgbench_init(scale=20)
22082209

22092210
replica=self.make_simple_node(
22102211
base_dir=os.path.join(self.module_name,self.fname,'replica'))
@@ -2251,7 +2252,7 @@ def test_archive_get_prefetch_corruption(self):
22512252

22522253
# generate WAL, copy it into prefetch directory, then corrupt
22532254
# some segment
2254-
node.pgbench_init(scale=20)
2255+
node.pgbench_init(scale=5)
22552256
sleep(20)
22562257

22572258
# now copy WAL files into prefetch directory and corrupt some of them
@@ -2304,18 +2305,20 @@ def test_archive_get_prefetch_corruption(self):
23042305
os.remove(os.path.join(replica.logs_dir,'postgresql.log'))
23052306
replica.slow_start(replica=True)
23062307

2307-
sleep(60)
2308-
2309-
withopen(os.path.join(replica.logs_dir,'postgresql.log'),'r')asf:
2310-
postgres_log_content=f.read()
2311-
2312-
self.assertIn(
2313-
'Prefetched WAL segment {0} is invalid, cannot use it'.format(filename),
2314-
postgres_log_content)
2315-
2316-
self.assertIn(
2317-
'LOG: restored log file "{0}" from archive'.format(filename),
2318-
postgres_log_content)
2308+
prefetch_line='Prefetched WAL segment {0} is invalid, cannot use it'.format(filename)
2309+
has_prefetch_line=False
2310+
restored_line='LOG: restored log file "{0}" from archive'.format(filename)
2311+
has_restored_line=False
2312+
forlineintail_file(os.path.join(replica.logs_dir,'postgresql.log')):
2313+
ifnothas_prefetch_line:
2314+
has_prefetch_line=prefetch_lineinline
2315+
ifnothas_restored_line:
2316+
has_restored_line=restored_lineinline
2317+
ifhas_prefetch_lineandhas_restored_line:
2318+
break
2319+
2320+
self.assertTrue(has_prefetch_line)
2321+
self.assertTrue(has_restored_line)
23192322

23202323
# @unittest.skip("skip")
23212324
deftest_archive_show_partial_files_handling(self):

‎tests/helpers/ptrack_helpers.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importhashlib
1111
importgetpass
1212
fromtimeimportsleep
13+
fromtimeimporttime
1314
importre
1415
importjson
1516
importrandom
@@ -130,6 +131,23 @@ def base36enc(number):
130131

131132
returnsign+base36
132133

134+
deftail_file(file,linetimeout=10,totaltimeout=60):
135+
start=time()
136+
withopen(file,'r')asf:
137+
waits=0
138+
whilewaits<linetimeout:
139+
line=f.readline()
140+
ifline=='':
141+
waits+=1
142+
sleep(1)
143+
continue
144+
waits=0
145+
yieldline
146+
iftime()-start>totaltimeout:
147+
raiseTimeoutError("total timeout tailing %s"%(file,))
148+
else:
149+
return# ok
150+
raiseTimeoutError("line timeout tailing %s"%(file,))
133151

134152
classProbackupException(Exception):
135153
def__init__(self,message,cmd):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp