File tree Expand file tree Collapse file tree 3 files changed +18
-31
lines changed Expand file tree Collapse file tree 3 files changed +18
-31
lines changed Original file line number Diff line number Diff line change @@ -847,8 +847,7 @@ def poll_query_until(self,
847
847
expected = True ,
848
848
commit = True ,
849
849
raise_programming_error = True ,
850
- raise_internal_error = True ,
851
- zero_rows_is_ok = False ):
850
+ raise_internal_error = True ):
852
851
"""
853
852
Run a query once per second until it returns 'expected'.
854
853
Query should return a single value (1 row, 1 column).
@@ -884,18 +883,14 @@ def poll_query_until(self,
884
883
if res is None :
885
884
raise QueryException ('Query returned None' , query )
886
885
887
- if len (res ) == 0 :
888
- if zero_rows_is_ok :
889
- time .sleep (sleep_time )
890
- attempts += 1
891
- continue
892
- else :
893
- raise QueryException ('Query returned 0 rows' , query )
894
-
895
- if len (res [0 ]) == 0 :
896
- raise QueryException ('Query returned 0 columns' , query )
897
-
898
- if res [0 ][0 ] == expected :
886
+ # result set is not empty
887
+ if len (res ):
888
+ if len (res [0 ]) == 0 :
889
+ raise QueryException ('Query returned 0 columns' , query )
890
+ if res [0 ][0 ] == expected :
891
+ return # done
892
+ # empty result set is considered as None
893
+ elif expected is None :
899
894
return # done
900
895
901
896
except ProgrammingError as e :
Original file line number Diff line number Diff line change @@ -138,24 +138,17 @@ def catchup(self, username=None):
138
138
Args:
139
139
username: remote node's user name
140
140
"""
141
- if pg_version_ge ('10' ):
142
- query = (
143
- "select pg_current_wal_lsn() - replay_lsn = 0 "
144
- "from pg_stat_replication where application_name = '{}'"
145
- ).format (self .name )
146
- else :
147
- query = (
148
- "select pg_current_xlog_location() - replay_location = 0 "
149
- "from pg_stat_replication where application_name = '{}'"
150
- ).format (self .name )
141
+ query = (
142
+ "select pg_current_wal_lsn() - replay_lsn = 0 "
143
+ "from pg_stat_replication where application_name = '{}'"
144
+ ).format (self .name )
151
145
152
146
try :
153
147
# wait until this LSN reaches subscriber
154
148
self .pub .node .poll_query_until (
155
149
query = query ,
156
150
dbname = self .pub .dbname ,
157
151
username = username or self .pub .username ,
158
- max_attempts = 60 ,
159
- zero_rows_is_ok = True ) # statistics may have not updated yet
152
+ max_attempts = 60 )
160
153
except Exception as e :
161
154
raise_from (CatchUpException ("Failed to catch up" , query ), e )
Original file line number Diff line number Diff line change @@ -495,11 +495,6 @@ def test_poll_query_until(self):
495
495
496
496
self .assertTrue (end_time - start_time >= 5 )
497
497
498
- # check 0 rows
499
- with self .assertRaises (QueryException ):
500
- node .poll_query_until (
501
- query = 'select * from pg_class where true = false' )
502
-
503
498
# check 0 columns
504
499
with self .assertRaises (QueryException ):
505
500
node .poll_query_until (query = 'select from pg_class limit 1' )
@@ -512,6 +507,10 @@ def test_poll_query_until(self):
512
507
node .poll_query_until (
513
508
query = 'create table def()' , expected = None ) # returns nothing
514
509
510
+ # check 0 rows equivalent to expected=None
511
+ node .poll_query_until (
512
+ query = 'select * from pg_class where true = false' , expected = None )
513
+
515
514
# check arbitrary expected value, fail
516
515
with self .assertRaises (TimeoutException ):
517
516
node .poll_query_until (
You can’t perform that action at this time.
0 commit comments