@@ -97,11 +97,11 @@ def test_simple_queries(self):
97
97
self .assertEqual (res , b'1\n ' )
98
98
99
99
res = node .execute ('postgres' , 'select 1' )
100
- self .assertEqual (res , ([ 1 ] , ))
100
+ self .assertListEqual (res , [( 1 , )] )
101
101
102
102
with node .connect ('postgres' ) as con :
103
103
res = con .execute ('select 1' )
104
- self .assertEqual (res , ([ 1 ] , ))
104
+ self .assertListEqual (res , [( 1 , )] )
105
105
106
106
def test_transactions (self ):
107
107
with get_new_node ('test' ) as node :
@@ -116,12 +116,12 @@ def test_transactions(self):
116
116
con .begin ()
117
117
con .execute ('insert into test values (2)' )
118
118
res = con .execute ('select * from test order by val asc' )
119
- self .assertEqual (res , ([ 1 ], [ 2 ]) )
119
+ self .assertListEqual (res , [( 1 , ), ( 2 , )] )
120
120
con .rollback ()
121
121
122
122
con .begin ()
123
123
res = con .execute ('select * from test' )
124
- self .assertEqual (res , ([ 1 ] , ))
124
+ self .assertListEqual (res , [( 1 , )] )
125
125
con .rollback ()
126
126
127
127
con .begin ()
@@ -165,7 +165,7 @@ def test_backup_simple(self):
165
165
slave .start ()
166
166
res = slave .execute ('postgres' ,
167
167
'select * from test order by i asc' )
168
- self .assertEqual (res , ([ 1 ], [ 2 ], [ 3 ], [ 4 ]) )
168
+ self .assertListEqual (res , [( 1 , ), ( 2 , ), ( 3 , ), ( 4 , )] )
169
169
170
170
def test_backup_multiple (self ):
171
171
with get_new_node ('node' ) as node :
@@ -210,53 +210,52 @@ def test_backup_and_replication(self):
210
210
211
211
backup = node .backup ()
212
212
213
- replica = backup .spawn_replica ('replica' )
214
- replica .start ()
215
- res = replica .execute ('postgres' , 'select * from abc' )
216
- self .assertEqual (len (res ), 1 )
217
- self .assertEqual (res [0 ][0 ], 1 )
218
- self .assertEqual (res [0 ][1 ], 2 )
219
-
220
- cur_ver = LooseVersion (get_pg_config ()['VERSION_NUM' ])
221
- min_ver = LooseVersion ('10' )
222
-
223
- # Prepare the query which would check whether record reached replica
224
- # (It is slightly different for Postgres 9.6 and Postgres 10+)
225
- if cur_ver >= min_ver :
226
- wait_lsn = 'SELECT pg_current_wal_lsn() <= replay_lsn ' \
227
- 'FROM pg_stat_replication WHERE application_name = \' %s\' ' \
228
- % replica .name
229
- else :
230
- wait_lsn = 'SELECT pg_current_xlog_location() <= replay_location ' \
231
- 'FROM pg_stat_replication WHERE application_name = \' %s\' ' \
232
- % replica .name
233
-
234
- # Insert into master node
235
- node .psql ('postgres' , 'insert into abc values (3, 4)' )
236
- # Wait until data syncronizes
237
- node .poll_query_until ('postgres' , wait_lsn )
238
- # Check that this record was exported to replica
239
- res = replica .execute ('postgres' , 'select * from abc' )
240
- self .assertEqual (len (res ), 2 )
241
- self .assertEqual (res [1 ][0 ], 3 )
242
- self .assertEqual (res [1 ][1 ], 4 )
243
-
244
- # check manual cleanup
245
- replica .cleanup ()
246
- replica .free_port ()
213
+ with backup .spawn_replica ('replica' ) as replica :
214
+ replica .start ()
215
+ res = replica .execute ('postgres' , 'select * from abc' )
216
+ self .assertListEqual (res , [(1 , 2 )])
217
+
218
+ cur_ver = LooseVersion (get_pg_config ()['VERSION_NUM' ])
219
+ min_ver = LooseVersion ('10' )
220
+
221
+ # Prepare the query which would check whether record reached replica
222
+ # (It is slightly different for Postgres 9.6 and Postgres 10+)
223
+ if cur_ver >= min_ver :
224
+ wait_lsn = 'SELECT pg_current_wal_lsn() <= replay_lsn ' \
225
+ 'FROM pg_stat_replication WHERE application_name = \' %s\' ' \
226
+ % replica .name
227
+ else :
228
+ wait_lsn = 'SELECT pg_current_xlog_location() <= replay_location ' \
229
+ 'FROM pg_stat_replication WHERE application_name = \' %s\' ' \
230
+ % replica .name
231
+
232
+ # Insert into master node
233
+ node .psql ('postgres' , 'insert into abc values (3, 4)' )
234
+ # Wait until data syncronizes
235
+ node .poll_query_until ('postgres' , wait_lsn )
236
+ # Check that this record was exported to replica
237
+ res = replica .execute ('postgres' , 'select * from abc' )
238
+ self .assertListEqual (res , [(1 , 2 ), (3 , 4 )])
247
239
248
240
def test_dump (self ):
249
- with get_new_node ('test' ) as node :
250
- node .init ().start ()
251
- node .safe_psql (
252
- 'postgres' , 'create table abc as '
253
- 'select g as a, g as b from generate_series(1, 10) as g' )
254
- node .psql ('postgres' , 'create database test' )
255
- node .dump ('postgres' , 'test.sql' )
256
- node .restore ('test' , 'test.sql' )
257
- self .assertEqual (
258
- node .psql ('postgres' , 'select * from abc' ),
259
- node .psql ('test' , 'select * from abc' ), )
241
+ with get_new_node ('node1' ) as node1 :
242
+ node1 .init ().start ()
243
+
244
+ with node1 .connect ('postgres' ) as con :
245
+ con .begin ()
246
+ con .execute ('create table test (val int)' )
247
+ con .execute ('insert into test values (1), (2)' )
248
+ con .commit ()
249
+
250
+ # take a new dump
251
+ dump = node1 .dump ('postgres' )
252
+
253
+ with get_new_node ('node2' ) as node2 :
254
+ node2 .init ().start ().restore ('postgres' , dump )
255
+
256
+ res = node2 .execute ('postgres' ,
257
+ 'select * from test order by val asc' )
258
+ self .assertListEqual (res , [(1 , ), (2 , )])
260
259
261
260
def test_users (self ):
262
261
with get_new_node ('master' ) as node :
0 commit comments