Skip to content

Commit 077ab7a

Browse files
committed
test: avoid sleeping in truncate test to flakiness
We only need to ensure the truncate succeeds fast, not necessary to sleep. Also adjust sleep time of test_http_responses_will_delete_despite_restart.
1 parent bd786ce commit 077ab7a

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

test/test_http_requests_deleted_after_ttl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_http_responses_will_delete_despite_restart(sess, autocommit_sess):
169169
autocommit_sess.execute(text("select net.wait_until_running()"))
170170

171171
# wait for ttl
172-
time.sleep(1)
172+
time.sleep(1.1)
173173

174174
(count,) = sess.execute(
175175
text(

test/test_worker_behavior.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -169,52 +169,27 @@ def test_can_delete_rows_while_processing_queue(sess, autocommit_sess):
169169
def test_truncate_wait_while_processing_queue(sess, autocommit_sess):
170170
"""a truncate will not wait until the worker is done processing all requests"""
171171

172+
# ensure the worker will be processing the queue 1 by 1 (slowly) so it doesn't clear the whole
173+
# net.http_request_queue in one go
172174
autocommit_sess.execute(text("alter system set pg_net.batch_size to '1';"))
173175
autocommit_sess.execute(text("select net.worker_restart();"))
174176
autocommit_sess.execute(text("select net.wait_until_running();"))
175177

176178
sess.execute(text(
177179
"""
178-
select net.http_get('http://localhost:8080/pathological?status=200') from generate_series(1,5);
180+
select net.http_get('http://localhost:8080/pathological?status=200') from generate_series(1,10);
179181
"""
180182
))
181-
182183
sess.commit()
183184

184-
# truncate succeeds
185+
# truncate succeeds fast, despite the worker still processing the queue 1 by 1
185186
sess.execute(text(
186187
"""
187188
truncate net.http_request_queue;
188189
"""
189190
))
190191

191-
sess.commit()
192-
193-
time.sleep(0.1)
194-
195-
# and only one response will be done
196-
(count,) = sess.execute(text(
197-
"""
198-
select count(*) from net._http_response;
199-
"""
200-
)).fetchone()
201-
assert count == 1
202-
203-
sess.commit()
204-
205-
# even if some time passes
206-
time.sleep(1.1)
207-
208-
(count,) = sess.execute(text(
209-
"""
210-
select count(*) from net._http_response;
211-
"""
212-
)).fetchone()
213-
assert count == 1
214-
215-
sess.commit()
216-
217-
# and the queue will be empty
192+
# now the queue will be empty
218193
(count,) = sess.execute(text(
219194
"""
220195
select count(*) from net.http_request_queue;

0 commit comments

Comments
 (0)