Skip to content

Commit 7021cf4

Browse files
committed
fix: check_worker_is_up
* Test it works, previously it only tested failure.
1 parent 2008e58 commit 7021cf4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sql/pg_net.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ create unlogged table net.http_request_queue(
2020

2121
create or replace function net.check_worker_is_up() returns void as $$
2222
begin
23-
if not exists (select pid from pg_stat_activity where backend_type = 'pg_net worker') then
23+
if not exists (select pid from pg_stat_activity where backend_type ilike '%pg_net%') then
2424
raise exception using
2525
message = 'the pg_net background worker is not up'
2626
, detail = 'the pg_net background worker is down due to an internal error and cannot process requests'
2727
, hint = 'make sure that you didn''t modify any of pg_net internal tables';
2828
end if;
2929
end
3030
$$ language plpgsql;
31+
comment on function net.check_worker_is_up() is 'raises an exception if the pg_net background worker is not up, otherwise it doesn''t return anything';
3132

3233
-- Associates a response with a request
3334
-- API: Private

test/test_worker_error.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
import pytest
33
import time
44

5+
def test_success_when_worker_is_up(sess):
6+
"""net.check_worker_is_up should not return anything when the worker is running"""
7+
8+
(result,) = sess.execute(
9+
"""
10+
select net.check_worker_is_up();
11+
"""
12+
).fetchone()
13+
assert result is not None
14+
assert result == ''
15+
516
def test_http_get_error_when_worker_down(sess):
617
"""net.http_get returns an error when pg background worker is down"""
718

819
# kill the bg worker manually
920
sess.execute(text("""
10-
select pg_terminate_backend((select pid from pg_stat_activity where backend_type = 'pg_net worker'));
21+
select pg_terminate_backend((select pid from pg_stat_activity where backend_type ilike '%pg_net%'));
1122
"""))
1223

1324
time.sleep(1);

0 commit comments

Comments
 (0)