Skip to content

Commit 0e56cb0

Browse files
committed
test: make timeout test faster and shorten query
1 parent 130f839 commit 0e56cb0

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

test/test_http_timeout.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,29 @@ def test_many_slow_mixed_with_fast(sess):
5656
"""many fast responses finish despite being mixed with slow responses, the fast responses will wait the timeout duration"""
5757

5858
sess.execute(text(
59-
"""
60-
select
61-
net.http_get(url := 'http://localhost:8080/pathological?status=200')
62-
, net.http_get(url := 'http://localhost:8080/pathological?status=200&delay=10')
63-
, net.http_get(url := 'http://localhost:8080/pathological?status=200')
64-
, net.http_get(url := 'http://localhost:8080/pathological?status=200&delay=10')
65-
from generate_series(1,25) _;
59+
"""
60+
select
61+
net.http_get(url := 'http://localhost:8080/pathological?status=200')
62+
, net.http_get(url := 'http://localhost:8080/pathological?status=200&delay=2', timeout_milliseconds := 1000)
63+
, net.http_get(url := 'http://localhost:8080/pathological?status=200')
64+
, net.http_get(url := 'http://localhost:8080/pathological?status=200&delay=2', timeout_milliseconds := 1000)
65+
from generate_series(1,25) _;
6666
"""
6767
))
6868

6969
sess.commit()
7070

71-
# wait for timeout
72-
time.sleep(6)
71+
# wait for timeouts
72+
time.sleep(3)
7373

74-
(status_code,count) = sess.execute(text(
74+
(request_successes, request_timeouts) = sess.execute(text(
7575
"""
76-
select status_code, count(*) from net._http_response where status_code = 200 group by status_code;
76+
select
77+
count(*) filter (where error_msg is null and status_code = 200) as request_successes,
78+
count(*) filter (where error_msg is not null and error_msg like 'Timeout was reached') as request_timeouts
79+
from net._http_response;
7780
"""
7881
)).fetchone()
7982

80-
assert status_code == 200
81-
assert count == 50
82-
83-
(timed_out_count,) = sess.execute(text(
84-
"""
85-
select count(*) from net._http_response where error_msg ilike '%Timeout%';
86-
"""
87-
)).fetchone()
88-
assert timed_out_count == 50
83+
assert request_successes == 50
84+
assert request_timeouts == 50

test/test_worker_error.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ def test_success_when_worker_is_up(sess):
1111
assert result is not None
1212
assert result == ''
1313

14+
1415
def test_http_get_error_when_worker_down(sess):
1516
"""net.http_get returns an error when pg background worker is down"""
1617

17-
sess.execute(text("""
18+
(restarted,) = sess.execute(text("""
1819
select net.worker_restart();
19-
"""))
20+
""")).fetchone()
21+
assert restarted is not None
22+
assert restarted == True
2023

2124
time.sleep(0.1)
2225

0 commit comments

Comments
 (0)