@@ -40,7 +40,8 @@ function count_allocs(f, args...)
40
40
return Base. gc_alloc_count (stats. gcstats)
41
41
end
42
42
43
- @testset " LibPQ" begin
43
+ usenonblocking = get (ENV , " usenonblocking" , false )
44
+ @testset " LibPQ $(usenonblocking ? " (nonblocking connection)" : " " ) " begin
44
45
45
46
@testset " ConninfoDisplay" begin
46
47
@test parse (LibPQ. ConninfoDisplay, " " ) == LibPQ. Normal
82
83
83
84
@testset " Example SELECT" begin
84
85
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= false )
86
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
85
87
@test conn isa LibPQ. Connection
86
88
@test isopen (conn)
87
89
@test status (conn) == LibPQ. libpq_c. CONNECTION_OK
190
192
191
193
@testset " Example INSERT and DELETE" begin
192
194
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
195
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
193
196
194
197
result = execute (conn, """
195
198
CREATE TEMPORARY TABLE libpqjl_test (
333
336
@testset " load!" begin
334
337
@testset " issue #204" begin
335
338
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
339
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
336
340
337
341
close (execute (conn, """
338
342
CREATE TEMPORARY TABLE libpqjl_test (
357
361
@testset " COPY FROM" begin
358
362
@testset " Example COPY FROM" begin
359
363
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
364
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
360
365
361
366
result = execute (conn, """
362
367
CREATE TEMPORARY TABLE libpqjl_test (
401
406
402
407
@testset " Wrong column order" begin
403
408
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
409
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
404
410
405
411
result = execute (conn, """
406
412
CREATE TEMPORARY TABLE libpqjl_test (
458
464
local saved_conn
459
465
460
466
was_open = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true ) do jl_conn
467
+ LibPQ. setnonblocking (jl_conn, nonblock= usenonblocking)
461
468
saved_conn = jl_conn
462
469
return isopen (jl_conn)
463
470
end
466
473
@test ! isopen (saved_conn)
467
474
468
475
@test_throws LibPQ. Errors. PQConnectionError LibPQ. Connection (" dbname=123fake user=$DATABASE_USER " ; throw_error= true ) do jl_conn
476
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
469
477
saved_conn = jl_conn
470
478
@test false
471
479
end
@@ -475,13 +483,15 @@ end
475
483
476
484
@testset " Version Numbers" begin
477
485
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
486
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
478
487
479
488
# update this test before PostgreSQL 20.0 ;)
480
489
@test LibPQ. pqv " 7" <= LibPQ. server_version (conn) <= LibPQ. pqv " 20"
481
490
end
482
491
483
492
@testset " Encoding" begin
484
493
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
494
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
485
495
486
496
@test LibPQ. encoding (conn) == " UTF8"
487
497
513
523
throw_error= true ,
514
524
type_map= Dict (:interval => String),
515
525
)
526
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
516
527
517
528
conn_info = LibPQ. conninfo (conn)
518
529
options = first (filter (conn_info) do conn_opt
632
643
@testset " Finalizer" begin
633
644
closed_flags = map (1 : 50 ) do _
634
645
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
646
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
647
+
635
648
closed = conn. closed
636
649
finalize (conn)
637
650
return closed
646
659
647
660
closed_flags = map (1 : 50 ) do _
648
661
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
662
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
663
+
649
664
push! (results, execute (conn, " SELECT 1;" ))
650
665
return conn. closed
651
666
end
661
676
# with AsyncResults, which hold a reference to Connection
662
677
closed_flags = asyncmap (1 : 50 ) do _
663
678
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
679
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
680
+
664
681
wait (async_execute (conn, " SELECT pg_sleep(1);" ))
665
682
return conn. closed
666
683
end
707
724
708
725
@testset " throw_error=false" begin
709
726
conn = LibPQ. Connection (" dbname=123fake user=$DATABASE_USER " ; throw_error= false )
727
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
728
+
710
729
@test conn isa LibPQ. Connection
711
730
@test status (conn) == LibPQ. libpq_c. CONNECTION_BAD
712
731
@test isopen (conn)
725
744
@test_throws LibPQ. Errors. PQConnectionError LibPQ. Connection (" dbname=123fake user=$DATABASE_USER " ; throw_error= true )
726
745
727
746
conn = LibPQ. Connection (" dbname=123fake user=$DATABASE_USER " ; throw_error= false )
747
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
748
+
728
749
@test conn isa LibPQ. Connection
729
750
@test status (conn) == LibPQ. libpq_c. CONNECTION_BAD
730
751
@test isopen (conn)
740
761
@testset " Results" begin
741
762
@testset " Nulls" begin
742
763
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
764
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
743
765
744
766
result = execute (conn, " SELECT NULL" ; throw_error= true )
745
767
@test status (result) == LibPQ. libpq_c. PGRES_TUPLES_OK
824
846
825
847
@testset " Not Nulls" begin
826
848
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
849
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
827
850
828
851
result = execute (conn, " SELECT NULL" ; not_null= [false ], throw_error= true )
829
852
@test status (result) == LibPQ. libpq_c. PGRES_TUPLES_OK
949
972
950
973
@testset " Tables.jl" begin
951
974
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
975
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
952
976
953
977
result = execute (conn, """
954
978
SELECT no_nulls, yes_nulls FROM (
991
1015
992
1016
@testset " Duplicate names" begin
993
1017
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1018
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
994
1019
995
1020
result = execute (conn, " SELECT 1 AS col, 2 AS col;" , not_null= true , throw_error= true )
996
1021
columns = Tables. columns (result)
@@ -1007,6 +1032,7 @@ end
1007
1032
1008
1033
@testset " Uppercase Columns" begin
1009
1034
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1035
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1010
1036
1011
1037
result = execute (conn, " SELECT 1 AS \" Column\" ;" )
1012
1038
@test num_columns (result) == 1
@@ -1025,6 +1051,7 @@ end
1025
1051
1026
1052
@testset " PQResultError" begin
1027
1053
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1054
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1028
1055
1029
1056
try
1030
1057
execute (conn, " SELECT log(-1);" )
@@ -1072,6 +1099,7 @@ end
1072
1099
@testset " Type Conversions" begin
1073
1100
@testset " Deprecations" begin
1074
1101
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1102
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1075
1103
1076
1104
result = execute (conn, " SELECT 'infinity'::timestamp;" )
1077
1105
@@ -1089,6 +1117,7 @@ end
1089
1117
1090
1118
@testset " Automatic" begin
1091
1119
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1120
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1092
1121
1093
1122
result = execute (conn, """
1094
1123
SELECT oid, typname, typlen, typbyval, typcategory
@@ -1120,6 +1149,7 @@ end
1120
1149
1121
1150
@testset " Overrides" begin
1122
1151
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1152
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1123
1153
1124
1154
result = execute (conn, " SELECT 4::bigint;" )
1125
1155
@test first (first (result)) === Int64 (4 )
@@ -1169,6 +1199,7 @@ end
1169
1199
@testset for binary_format in (LibPQ. TEXT, LibPQ. BINARY)
1170
1200
@testset " Default Types" begin
1171
1201
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1202
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1172
1203
1173
1204
test_data = [
1174
1205
(" 3" , Cint (3 )),
@@ -1335,6 +1366,7 @@ end
1335
1366
1336
1367
@testset " Specified Types" begin
1337
1368
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1369
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1338
1370
1339
1371
test_data = [
1340
1372
(" 3" , UInt, UInt (3 )),
@@ -1428,6 +1460,7 @@ end
1428
1460
1429
1461
@testset " Parameters" begin
1430
1462
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1463
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1431
1464
1432
1465
@testset " Arrays" begin
1433
1466
tests = (
@@ -1542,6 +1575,7 @@ end
1542
1575
1543
1576
@testset " SQLString" begin
1544
1577
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
1578
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1545
1579
1546
1580
execute (conn, sql ```
1547
1581
CREATE TEMPORARY TABLE libpq_test_users (
@@ -1577,6 +1611,7 @@ end
1577
1611
@testset " Query Errors" begin
1578
1612
@testset " Syntax Errors" begin
1579
1613
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1614
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1580
1615
1581
1616
result = execute (conn, " SELORCT NUUL;" ; throw_error= false )
1582
1617
@test status (result) == LibPQ. libpq_c. PGRES_FATAL_ERROR
@@ -1595,6 +1630,7 @@ end
1595
1630
1596
1631
@testset " Wrong No. Parameters" begin
1597
1632
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1633
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1598
1634
1599
1635
result = execute (conn, " SELORCT \$ 1;" , String[]; throw_error= false )
1600
1636
@test status (result) == LibPQ. libpq_c. PGRES_FATAL_ERROR
@@ -1619,6 +1655,7 @@ end
1619
1655
1620
1656
@testset " Interface Errors" begin
1621
1657
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1658
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1622
1659
1623
1660
result = execute (
1624
1661
conn,
@@ -1652,6 +1689,7 @@ end
1652
1689
1653
1690
# Establish connection and construct temporary table.
1654
1691
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " )
1692
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1655
1693
1656
1694
# Get the column.
1657
1695
result = execute (
@@ -1678,6 +1716,7 @@ end
1678
1716
@testset " Statements" begin
1679
1717
@testset " No Params, Output" begin
1680
1718
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1719
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1681
1720
1682
1721
stmt = prepare (conn, " SELECT oid, typname FROM pg_type" )
1683
1722
@@ -1699,6 +1738,7 @@ end
1699
1738
1700
1739
@testset " Params, Output" begin
1701
1740
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1741
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1702
1742
1703
1743
stmt = prepare (conn, " SELECT oid, typname FROM pg_type WHERE oid = \$ 1" )
1704
1744
@@ -1723,11 +1763,13 @@ end
1723
1763
end
1724
1764
end
1725
1765
1726
- @testset " AsyncResults" begin
1766
+ @testset " AsyncResults (usenonblocking connection=$usenonblocking )" for usenonblocking in [true , false ]
1767
+ @info " usenonblocking" usenonblocking
1727
1768
trywait (ar:: LibPQ.AsyncResult ) = (try wait (ar) catch end ; nothing )
1728
1769
1729
1770
@testset " Basic" begin
1730
1771
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1772
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1731
1773
1732
1774
ar = async_execute (conn, " SELECT pg_sleep(2);" ; throw_error= false )
1733
1775
yield ()
@@ -1750,6 +1792,7 @@ end
1750
1792
1751
1793
@testset " Parameters" begin
1752
1794
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1795
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1753
1796
1754
1797
ar = async_execute (
1755
1798
conn,
@@ -1782,6 +1825,7 @@ end
1782
1825
# Ensures queries wait for previous query completion before starting
1783
1826
@testset " Wait in line to complete" begin
1784
1827
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1828
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1785
1829
1786
1830
first_ar = async_execute (conn, " SELECT pg_sleep(4);" )
1787
1831
yield ()
@@ -1811,6 +1855,7 @@ end
1811
1855
1812
1856
@testset " Cancel" begin
1813
1857
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1858
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1814
1859
1815
1860
# final query needs to be one that actually does something
1816
1861
# on Windows, first query also needs to do something
@@ -1843,6 +1888,7 @@ end
1843
1888
1844
1889
@testset " Canceled by closing connection" begin
1845
1890
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1891
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1846
1892
1847
1893
# final query needs to be one that actually does something
1848
1894
# on Windows, first query also needs to do something
@@ -1875,6 +1921,7 @@ end
1875
1921
1876
1922
@testset " FDWatcher: bad file descriptor (EBADF)" begin
1877
1923
conn = LibPQ. Connection (" dbname=postgres user=$DATABASE_USER " ; throw_error= true )
1924
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1878
1925
1879
1926
ar = async_execute (conn, " SELECT pg_sleep(3); SELECT * FROM pg_type;" )
1880
1927
yield ()
@@ -1898,6 +1945,7 @@ end
1898
1945
@testset " DBInterface integration" begin
1899
1946
conn = DBInterface. connect (LibPQ. Connection, " dbname=postgres user=$DATABASE_USER " )
1900
1947
@test conn isa LibPQ. Connection
1948
+ LibPQ. setnonblocking (conn, nonblock= usenonblocking)
1901
1949
1902
1950
result = DBInterface. execute (
1903
1951
conn,
0 commit comments