@@ -683,13 +683,16 @@ def test_pool_acquisition_timeout(level, defaultenv, metapostgrest):
683
683
assert data ["message" ] == "Timed out acquiring connection from connection pool."
684
684
685
685
# ensure the message appears on the logs as well
686
- output = sorted (postgrest .read_stdout (nlines = 3 ))
686
+ output = sorted (postgrest .read_stdout (nlines = 10 ))
687
687
688
688
if level == "crit" :
689
689
assert len (output ) == 0
690
690
else :
691
- assert " 504 " in output [0 ]
692
- assert "Timed out acquiring connection from connection pool." in output [2 ]
691
+ assert any (" 504 " in line for line in output )
692
+ assert any (
693
+ "Timed out acquiring connection from connection pool." in line
694
+ for line in output
695
+ )
693
696
694
697
695
698
def test_change_statement_timeout_held_connection (defaultenv , metapostgrest ):
@@ -974,9 +977,9 @@ def test_log_level(level, defaultenv):
974
977
output [2 ],
975
978
)
976
979
977
- assert len (output ) == 5
978
- assert "Connection" and "is available" in output [ 3 ]
979
- assert "Connection" and "is used" in output [ 4 ]
980
+ assert len (output ) == 7
981
+ assert any ( "Connection" and "is available" in line for line in output )
982
+ assert any ( "Connection" and "is used" in line for line in output )
980
983
981
984
982
985
@pytest .mark .parametrize ("level" , ["crit" , "error" , "warn" , "info" , "debug" ])
@@ -1023,13 +1026,15 @@ def test_log_query(level, defaultenv):
1023
1026
assert re .match (infinite_recursion_5xx_regx , output [5 ])
1024
1027
assert len (output ) == 6
1025
1028
elif level == "debug" :
1026
- output_ok = postgrest .read_stdout (nlines = 8 )
1027
- assert re .match (root_2xx_regx , output_ok [2 ])
1028
- assert re .match (get_2xx_regx , output_ok [6 ])
1029
- assert len (output_ok ) == 8
1030
- output_err = postgrest .read_stdout (nlines = 4 )
1031
- assert re .match (infinite_recursion_5xx_regx , output_err [3 ])
1032
- assert len (output_err ) == 4
1029
+ output_root = postgrest .read_stdout (nlines = 6 )
1030
+ assert re .match (root_2xx_regx , output_root [4 ])
1031
+ assert len (output_root ) == 6
1032
+ output_get = postgrest .read_stdout (nlines = 6 )
1033
+ assert re .match (get_2xx_regx , output_get [4 ])
1034
+ assert len (output_get ) == 6
1035
+ output_err = postgrest .read_stdout (nlines = 6 )
1036
+ assert re .match (infinite_recursion_5xx_regx , output_err [5 ])
1037
+ assert len (output_err ) == 6
1033
1038
1034
1039
1035
1040
def test_no_pool_connection_required_on_bad_http_logic (defaultenv ):
@@ -1570,13 +1575,13 @@ def test_db_error_logging_to_stderr(level, defaultenv, metapostgrest):
1570
1575
assert response .status_code == 500
1571
1576
1572
1577
# ensure the message appears on the logs
1573
- output = sorted (postgrest .read_stdout (nlines = 4 ))
1578
+ output = sorted (postgrest .read_stdout (nlines = 6 ))
1574
1579
1575
1580
if level == "crit" :
1576
1581
assert len (output ) == 0
1577
1582
elif level == "debug" :
1578
1583
assert " 500 " in output [0 ]
1579
- assert "canceling statement due to statement timeout" in output [3 ]
1584
+ assert "canceling statement due to statement timeout" in output [5 ]
1580
1585
else :
1581
1586
assert " 500 " in output [0 ]
1582
1587
assert "canceling statement due to statement timeout" in output [1 ]
@@ -1767,3 +1772,31 @@ def test_pgrst_log_503_client_error_to_stderr(defaultenv):
1767
1772
log_message = '{"code":"PGRST001","details":"no connection to the server\\ n","hint":null,"message":"Database client error. Retrying the connection."}\n '
1768
1773
1769
1774
assert any (log_message in line for line in output )
1775
+
1776
+
1777
+ @pytest .mark .parametrize ("level" , ["crit" , "error" , "warn" , "info" , "debug" ])
1778
+ def test_log_pool_req_observation (level , defaultenv ):
1779
+ "PostgREST should log PoolRequest and PoolRequestFullfilled observation when log-level=debug"
1780
+
1781
+ env = {** defaultenv , "PGRST_LOG_LEVEL" : level , "PGRST_JWT_SECRET" : SECRET }
1782
+
1783
+ headers = jwtauthheader ({"role" : "postgrest_test_author" }, SECRET )
1784
+
1785
+ pool_req = "Trying to borrow a connection from pool"
1786
+ pool_req_fullfill = "Borrowed a connection from the pool"
1787
+
1788
+ with run (env = env ) as postgrest :
1789
+
1790
+ postgrest .session .get ("/authors_only" , headers = headers )
1791
+
1792
+ if level == "debug" :
1793
+ output = postgrest .read_stdout (nlines = 4 )
1794
+ assert pool_req in output [0 ]
1795
+ assert pool_req_fullfill in output [3 ]
1796
+ assert len (output ) == 4
1797
+ elif level == "info" :
1798
+ output = postgrest .read_stdout (nlines = 4 )
1799
+ assert len (output ) == 1
1800
+ else :
1801
+ output = postgrest .read_stdout (nlines = 4 )
1802
+ assert len (output ) == 0
0 commit comments