@@ -226,3 +226,52 @@ def test_ptrack_threads_stream(self):
226226
227227 # Clean after yourself
228228 self .del_test_dir (module_name , fname )
229+
230+ # @unittest.skip("skip")
231+ def test_page_checksumm_fail (self ):
232+ """make node, corrupt some page, check that backup failed"""
233+ fname = self .id ().split ('.' )[3 ]
234+ node = self .make_simple_node (base_dir = "{0}/{1}/node" .format (module_name , fname ),
235+ set_replication = True ,
236+ initdb_params = ['--data-checksums' ],
237+ pg_options = {'wal_level' : 'replica' , 'max_wal_senders' : '2' }
238+ )
239+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
240+ self .init_pb (backup_dir )
241+ self .add_instance (backup_dir , 'node' , node )
242+ node .start ()
243+
244+ self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" , "--stream" ])
245+
246+ node .safe_psql (
247+ "postgres" ,
248+ "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,1000) i" )
249+ node .safe_psql (
250+ "postgres" ,
251+ "CHECKPOINT;" )
252+
253+ heap_path = node .safe_psql ("postgres" , "select pg_relation_filepath('t_heap')" ).rstrip ()
254+ node .stop ()
255+
256+ with open (os .path .join (node .data_dir ,heap_path ), "rb+" , 0 ) as f :
257+ f .seek (9000 )
258+ f .write (b"bla" )
259+ f .flush ()
260+ f .close
261+ node .start ()
262+
263+ try :
264+ self .backup_node (backup_dir , 'node' , node , backup_type = "full" , options = ["-j" , "4" , "--stream" ])
265+ # we should die here because exception is what we expect to happen
266+ self .assertEqual (1 , 0 , "Expecting Error because of page corruption in PostgreSQL instance.\n Output: {0} \n CMD: {1}" .format (
267+ repr (self .output ), self .cmd ))
268+ except ProbackupException as e :
269+ self .assertIn ("ERROR: File" , e .message ,
270+ "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
271+ self .assertIn ("blknum" , e .message ,
272+ "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
273+ self .assertIn ("have wrong checksum" , e .message ,
274+ "\n Unexpected Error Message: {0}\n CMD: {1}" .format (repr (e .message ), self .cmd ))
275+
276+ # Clean after yourself
277+ self .del_test_dir (module_name , fname )
0 commit comments