File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed
Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 1- shared_preload_libraries='pg_net'
1+ shared_preload_libraries='pg_net, pg_stat_statements '
22log_min_messages=INFO
Original file line number Diff line number Diff line change 1+ import time
2+
3+ import pytest
4+ from sqlalchemy import text
5+
6+ def test_query_stat_statements (sess ):
7+ """Check that the background worker executes queries despite no new requests arriving"""
8+
9+ (pg_version ,) = sess .execute (text (
10+ """
11+ select current_setting('server_version_num');
12+ """
13+ )).fetchone ()
14+
15+ if int (pg_version ) < 140000 :
16+ pytest .skip ("Skipping fixture on pg version < 14. The query_id column on pg_stat_statements is only available on >= 14" )
17+
18+ sess .execute (text (
19+ """
20+ create extension pg_stat_statements;
21+ """
22+ ))
23+
24+ sess .commit ()
25+
26+ time .sleep (1 )
27+
28+ (old_calls ,) = sess .execute (text (
29+ """
30+ select
31+ pss.calls
32+ from
33+ pg_stat_activity sa
34+ join
35+ pg_stat_statements pss
36+ on sa.query_id = pss.queryid
37+ where
38+ sa.backend_type ilike '%pg_net%';
39+ """
40+ )).fetchone ()
41+
42+ time .sleep (3 )
43+
44+ (new_calls ,) = sess .execute (text (
45+ """
46+ select
47+ pss.calls
48+ from
49+ pg_stat_activity sa
50+ join
51+ pg_stat_statements pss
52+ on sa.query_id = pss.queryid
53+ where
54+ sa.backend_type ilike '%pg_net%';
55+ """
56+ )).fetchone ()
57+
58+ assert new_calls > old_calls
You can’t perform that action at this time.
0 commit comments