Skip to content

Commit 8c7c19e

Browse files
committed
test: replace pathod with nginx for timeouts
Also ensure there are timeouts in the tests
1 parent 560837a commit 8c7c19e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/worker.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ static void insert_success_response(CurlData *cdata, long http_status_code, char
136136
, CStringGetDatum(cdata->body->data)
137137
, JsonbPGetDatum(jsonb_headers)
138138
, CStringGetDatum(contentType)
139-
// TODO Why is this hardcoded?
140-
, BoolGetDatum(false)
139+
, BoolGetDatum(false) // timed_out is false here as it's a success
141140
},
142141
(char[6]){
143142
' '

test/test_http_timeout.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_http_get_timeout_reached(sess):
88

99
(request_id,) = sess.execute(text(
1010
"""
11-
select net.http_get(url := 'http://localhost:9999/p/200:b"wait%20for%20six%20seconds"pr,6');
11+
select net.http_get(url := 'http://localhost:8080/pathological?status=200&delay=6');
1212
"""
1313
)).fetchone()
1414

@@ -33,35 +33,35 @@ def test_http_get_succeed_with_gt_timeout(sess):
3333

3434
(request_id,) = sess.execute(text(
3535
"""
36-
select net.http_get(url := 'http://localhost:9999/p/200:b"wait%20for%20three%20seconds"pr,3', timeout_milliseconds := 3500);
36+
select net.http_get(url := 'http://localhost:8080?status=200&delay=3', timeout_milliseconds := 3500);
3737
"""
3838
)).fetchone()
3939

4040
sess.commit()
4141

4242
time.sleep(4)
4343

44-
(response,) = sess.execute(
44+
(status_code,) = sess.execute(
4545
text(
4646
"""
47-
select content from net._http_response where id = :request_id;
47+
select status_code from net._http_response where id = :request_id;
4848
"""
4949
),
5050
{"request_id": request_id},
5151
).fetchone()
5252

53-
assert 'wait for three seconds' in str(response)
53+
assert status_code == 200
5454

5555
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(
5959
"""
6060
select
61-
net.http_get(url := 'http://localhost:9999/p/200')
62-
, net.http_get(url := 'http://localhost:9999/p/200:pr,f')
63-
, net.http_get(url := 'http://localhost:9999/p/200')
64-
, net.http_get(url := 'http://localhost:9999/p/200:pr,f')
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')
6565
from generate_series(1,25) _;
6666
"""
6767
))
@@ -79,3 +79,10 @@ def test_many_slow_mixed_with_fast(sess):
7979

8080
assert status_code == 200
8181
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

0 commit comments

Comments
 (0)