16
16
class ConcurrentTest (unittest .TestCase ):
17
17
18
18
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 = [
27
20
'create extension pg_pathman' ,
28
21
'create table abc(id serial, t text)' ,
29
22
'insert into abc select generate_series(1, 300000)' ,
30
23
'select create_hash_partitions(\' abc\' , \' id\' , 3, partition_data := false)' ,
31
24
]
32
25
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"""
33
45
node = get_new_node ('test' )
34
46
node .init ()
35
47
node .append_conf ('postgresql.conf' , 'shared_preload_libraries=\' pg_pathman\' \n ' )
36
48
node .start ()
37
-
38
- for cmd in setup_cmd :
39
- node .safe_psql ('postgres' , cmd )
49
+ self .init_test_data (node )
40
50
41
51
node .psql ('postgres' , 'select partition_data_worker(\' abc\' )' )
42
52
@@ -60,5 +70,41 @@ def test_concurrent(self):
60
70
61
71
node .stop ()
62
72
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
+
63
109
if __name__ == "__main__" :
64
110
unittest .main ()
0 commit comments