1616class ConcurrentTest (unittest .TestCase ):
1717
1818 def setUp (self ):
19- pass
20-
21- def tearDown (self ):
22- stop_all ()
23- # clean_all()
24-
25- def test_concurrent (self ):
26- setup_cmd = [
19+ self .setup_cmd = [
2720 'create extension pg_pathman' ,
2821 'create table abc(id serial, t text)' ,
2922 'insert into abc select generate_series(1, 300000)' ,
3023 'select create_hash_partitions(\' abc\' , \' id\' , 3, partition_data := false)' ,
3124 ]
3225
26+ def tearDown (self ):
27+ stop_all ()
28+ # clean_all()
29+
30+ def init_test_data (self , node ):
31+ """Initialize pg_pathman extension and test data"""
32+ for cmd in self .setup_cmd :
33+ node .safe_psql ('postgres' , cmd )
34+
35+ def catchup_replica (self , master , replica ):
36+ """Wait until replica synchronizes with master"""
37+ master .poll_query_until (
38+ 'postgres' ,
39+ 'SELECT pg_current_xlog_location() <= replay_location '
40+ 'FROM pg_stat_replication WHERE application_name = \' %s\' '
41+ % replica .name )
42+
43+ def test_concurrent (self ):
44+ """Tests concurrent partitioning"""
3345 node = get_new_node ('test' )
3446 node .init ()
3547 node .append_conf ('postgresql.conf' , 'shared_preload_libraries=\' pg_pathman\' \n ' )
3648 node .start ()
37-
38- for cmd in setup_cmd :
39- node .safe_psql ('postgres' , cmd )
49+ self .init_test_data (node )
4050
4151 node .psql ('postgres' , 'select partition_data_worker(\' abc\' )' )
4252
@@ -60,5 +70,41 @@ def test_concurrent(self):
6070
6171 node .stop ()
6272
73+ def test_replication (self ):
74+ """Tests how pg_pathman works with replication"""
75+ node = get_new_node ('master' )
76+ replica = get_new_node ('repl' )
77+
78+ # initialize master server
79+ node .init (allows_streaming = True )
80+ node .append_conf ('postgresql.conf' , 'shared_preload_libraries=\' pg_pathman\' \n ' )
81+ node .start ()
82+ node .backup ('my_backup' )
83+
84+ # initialize replica from backup
85+ replica .init_from_backup (node , 'my_backup' , has_streaming = True )
86+ replica .start ()
87+
88+ # initialize pg_pathman extension and some test data
89+ self .init_test_data (node )
90+
91+ # wait until replica catches up
92+ self .catchup_replica (node , replica )
93+
94+ # check that results are equal
95+ self .assertEqual (
96+ node .psql ('postgres' , 'explain (costs off) select * from abc' ),
97+ replica .psql ('postgres' , 'explain (costs off) select * from abc' )
98+ )
99+
100+ # enable parent and see if it is enabled in replica
101+ node .psql ('postgres' , 'select enable_parent(\' abc\' ' )
102+
103+ self .catchup_replica (node , replica )
104+ self .assertEqual (
105+ node .psql ('postgres' , 'explain (costs off) select * from abc' ),
106+ replica .psql ('postgres' , 'explain (costs off) select * from abc' )
107+ )
108+
63109if __name__ == "__main__" :
64110 unittest .main ()
0 commit comments